-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpyconschedulebuilder.py
217 lines (180 loc) · 5.63 KB
/
pyconschedulebuilder.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
""""
Goal is to talk a yaml file of talks data and produce
- responsive schedule
- talks page
- speakers page
- embeded videos
- all linked together
Schedule grid assumes talks don't end in the middle of other talks.
Layout alg is
[11-12
[11-11:30
"""
import yaml
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
with open('talks2019.yaml') as f:
data = yaml.load(f, Loader=Loader)
talks = sorted([t for t in data['talks'] if 'day' in t], key=lambda t: (t['day'],t['time'],t['dur'],t['track']))
tracks = data['tracks']
print(tracks)
sched = []
cur = None
for talk in talks:
if talk['time'] != cur:
cur = talk['time']
dur = talk['dur']
slot = dict(time=cur, dur=dur, talks=[])
sched.append(slot)
# now try to fit in the track
slot['talks'].append(talk)
print(talks)
sched
schedule = {}
currrow = 1
for s in sched:
time = s['time']
if not time in schedule: schedule[time] = []
for talk in s['talks']:
talk['row'] = currrow
talk['col'] = 1 if talk['track'] != 4 else 2
if 'track' in talk:
talk['subcol'] = 5 if type(talk['track']) == list else talk['track']
talk['colspan'] = 2 if talk['track'] == [1,2,3,4] else 1
else:
talk['subcol'] = 1
talk['colspan'] = 2
talk['time'] = time
if talk['subcol'] is None:
talk['subcol'] = 5
talk['colspan'] = 2
if not 'speaker' in talk or talk['speaker'] is None: talk['speaker'] = ""
if not 'description' in talk or talk['description'] is None: talk['description'] = ""
if not 'bio' in talk or talk['bio'] is None: talk['bio'] = ""
schedule[time].append(talk)
currrow += 1
html = '<h2>Tracks</h2>'
for track in tracks:
html += '<div class="schedule-item schedule-item-{}">{}</div>'.format(list(track.keys())[0],list(track.values())[0])
currday = ""
rowoffset = 0
for t in schedule:
s = schedule[t]
if len(s) == 0: continue
talk = s[0]
if talk['day'] != currday:
if currday != "": html += "</div>"
html += '<h2>' + talk['day'] + '</h2> <div class="grid-container">'
currday = talk['day']
rowoffset = talk['row']-1
subhtml = '<div class="timeflex" style="grid-row-start: {}; grid-row-end: {}; grid-column-start: {}; grid-column-end: {};"> <div class="timetext"><b>{}</b></div> <div class="schedule-item-container" style="flex-grow:1;">'.format(talk['row']-rowoffset,talk['row']-rowoffset,talk['col'],talk['col']+talk['colspan'],t)#,talk['row'],talk['row'],talk['col'],talk['col']+talk['colspan'])
for talk in s:
if talk['col'] == 1:
subhtml += ''' <div class="schedule-item schedule-item-{}" style="order: {};" onclick="var hid='hidden-field-{}-{}'; if (!$('#'+hid).hasClass('active')) $('#'+hid).fadeIn(250),$('#'+hid).addClass('active'); else $('#'+hid).fadeOut(250),$('#'+hid).removeClass('active');">
<div><b>{}</b></div>
<div>{}</div>
<div class="hidden-field" id="hidden-field-{}-{}">
<br>
<div><b>Description:</b></div>
<div>{}</div>
<br>
<div><b>Bio:</b></div>
<div>{}</div>
</div>
</div>'''.format(talk['subcol'],talk['subcol']-1,talk['row'],talk['subcol'],talk['title'],talk['speaker'],talk['row'],talk['subcol'],talk['description'],talk['bio'].strip() if 'bio' in talk else '')
subhtml += '</div> </div>'
for talk in s:
if talk['col'] == 2:
subhtml += ''' <div class="workshop-item" style="grid-row-start:{}; grid-row-end:{}; grid-column-start: {}; grid-column-end: {};" onclick="var hid='hidden-field-{}-{}'; if (!$('#'+hid).hasClass('active')) $('#'+hid).fadeIn(250),$('#'+hid).addClass('active'); else $('#'+hid).fadeOut(250),$('#'+hid).removeClass('active');">
<div class="workshop-text">
<b>{}</b><br>{}
<div class="hidden-field" id="hidden-field-{}-{}">
<br>
<div><b>Description:</b></div>
<div>{}</div>
<br>
<div><b>Bio:</b></div>
<div>{}</div>
</div>
</div>
</div>'''.format(talk['row']-rowoffset,talk['row']-rowoffset+3,talk['col'],talk['col'],talk['row'],talk['subcol'],talk['title'],talk['speaker'],talk['row'],talk['subcol'],talk['description'],talk['bio'].strip() if 'bio' in talk else '')
html += subhtml
print(html)
#Generate html file
htmlhead = '''
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="date" content="2018-05-23 22:28" />
<meta name="summary" content="Conference Schedule" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js"></script>
<style>
.grid-container {
width: 100%;
display: grid;
grid-template-columns: 60% auto;
grid-row-gap: 10px;
}
.timeflex {
display: flex;
flex-direction: row;
}
@media screen and (max-width: 500px) /* Mobile */ {
.timeflex {
flex-direction: column;
}
}
.schedule-item-container {
display:flex;
flex-direction: column;
}
.schedule-item {
padding: 5px;
padding-left: 10px;
color: white;
width: calc(100% - 20px);
margin-bottom: 5px;
}
.schedule-item:hover, .workshop-item:hover {
opacity: 0.8;
cursor: pointer;
}
.schedule-item-1 {
background-color: darkblue;
}
.schedule-item-2 {
background-color: darkgreen;
}
.schedule-item-3 {
background-color: darkred;
}
.schedule-item-5 {
background-color: gray;
}
.p-5 {
padding: 5px;
}
.workshop-item, .schedule-item-4 {
grid-column-start:3;
background-color: purple;
color: white;
margin-bottom: 5px;
padding: 10px;
margin-right: 5px;
}
.workshop-item .workshop-text {
}
.timetext {
padding-top: 5px;
padding-right: 5px;
}
a {
color: white;
}
.hidden-field {
display: none;
}
</style>
'''
with open('schedule_table.html','w') as f:
f.write(''+htmlhead+''+html+'')