-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph_viz.py
44 lines (35 loc) · 1.11 KB
/
graph_viz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from datetime import datetime
import gviz_api
import os
TIMETABLE_TEMPLATE_PATH = "./templates/timetable.html"
OUTPUT_DIRECTORY = "./output"
def generate(data, date):
page_template = ""
params = {}
date_string = date.strftime("%d-%m-%y")
# Creating the data
description = {
"room": ("string", "Room Name"),
"start": ("datetime", "Period Start"),
"end": ("datetime", "Period End")
}
# Loading it into gviz_api.DataTable
data_table = gviz_api.DataTable(description)
data_table.LoadData(data)
# Create a JSON string.
params["json"] = data_table.ToJSon(
columns_order=("room", "start", "end"),
order_by="room"
)
params["generated-date"] = datetime.now()
params["for-date"] = date_string
# Load Template file
with open(TIMETABLE_TEMPLATE_PATH, 'r') as f:
page_template = f.read()
try:
os.mkdir(OUTPUT_DIRECTORY)
except OSError:
pass
# Put JSON string into the template.
with open(os.path.join(OUTPUT_DIRECTORY, f"{date_string}.html"), 'w') as f:
f.write(page_template % params)