-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventBookletHTML.py
More file actions
executable file
·112 lines (94 loc) · 3.52 KB
/
EventBookletHTML.py
File metadata and controls
executable file
·112 lines (94 loc) · 3.52 KB
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
#!/usr/bin/python
import urllib2
import json
import codecs
import pprint
import time,datetime
import dateutil.parser
# Get an API Key from http://api.burningman.com
# Download camp and event data
req = codecs.open('camps.json', encoding='utf-8')
data = req.read()
camp_data = json.loads(data)
req = codecs.open('events.json', encoding='utf-8')
data = req.read()
event_data = json.loads(data)
pp = pprint.PrettyPrinter(indent=4)
camps = {}
events = []
time_format = "%Y-%m-%dT%H:%M:%S"
for c in camp_data:
uid = c['uid']
camps[uid] = {}
camps[uid]['name'] = c['name']
camps[uid]['location_string'] = c['location_string']
for e in event_data:
if 'occurrence_set' in e:
for o in e['occurrence_set']:
event = {}
event['start_time'] = dateutil.parser.parse(o['start_time'])
event['end_time'] = dateutil.parser.parse(o['end_time'])
event['title'] = e['title']
event['print_description'] = e['print_description']
event['description'] = e['description']
event['all_day'] = e['all_day']
if 'hosted_by_camp' in e:
event['hosted_by_camp'] = e['hosted_by_camp']
event['other_location'] = e['other_location']
event['label'] = e['event_type']['label']
events.append(event)
else:
print "No occurence for " + e['title']
# pp.pprint(events)
events = sorted(events, key=lambda event: event['all_day'], reverse=True)
events = sorted(events, key=lambda event: event['start_time'])
# pp.pprint(events)
prev_day = 0
prev_all_day = None
out = None
index = codecs.open('index.html', encoding='utf-8', mode='w')
index.write('<html><body>')
for e in events:
if e['start_time'].day != prev_day:
prev_day = e['start_time'].day
if out:
out.write('</body></html>')
out.close()
out = codecs.open(e['start_time'].strftime("%A-%m-%d") + '.html', encoding='utf-8', mode='w')
index.write('<li><a href="' + e['start_time'].strftime("%A-%m-%d") + '.html">' + e['start_time'].strftime("%A-%m-%d") + '</a></li>')
out.write('<html>\n')
out.write(' <head>\n')
out.write(' <meta http-equiv="Content-Type" content="text/html; charset=utf-8">')
out.write(' <link rel="stylesheet" href="style.css" type="text/css" media="screen"/>\n')
out.write(' <link rel="stylesheet" href="style.css" type="text/css" media="print"/>\n')
out.write(' <title>' + e['start_time'].strftime("%A %m/%d") + '</title>\n')
out.write(' </head>\n')
out.write(' <body>\n')
out.write('<h1>' + e['start_time'].strftime("%A %m/%d") + "</h1>")
out.write('<div><table>\n')
out.write(' <tr>\n')
out.write(' <td class="when">')
if e['all_day']:
out.write('All Day')
else:
out.write(e['start_time'].strftime("%H:%M") + " - " + e['end_time'].strftime("%H:%M"))
out.write('</td>\n <td class="what">' + e['title'] + '</td>\n')
out.write(' </tr>\n <tr>\n')
out.write(' <td class="where">')
has_location = False
if 'hosted_by_camp' in e:
uid = e['hosted_by_camp']
if uid in camps:
out.write(camps[uid]['name'] + '<br/>')
if camps[uid]['location_string']:
has_location = True
out.write(camps[uid]['location_string'] + '<br/>')
if not has_location:
out.write(e['other_location'] +'<br/>')
if e['label'] != 'None':
out.write(e['label'] + '<br/>')
out.write('</td>\n')
out.write(' <td class="why">' + e['description'] + '</td>\n')
out.write(' </tr>')
out.write('</table></div>\n')
index.write('</body></html>')