-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.py
More file actions
77 lines (65 loc) · 2.46 KB
/
build.py
File metadata and controls
77 lines (65 loc) · 2.46 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
import os
from collections import OrderedDict
from datetime import datetime
import arrow
import frontmatter
import requests
from jinja2 import Environment, FileSystemLoader
AIRTABLE_API_KEY = os.environ['AIRTABLE_API_KEY']
AIRTABLE_ENDPOINT = os.environ['AIRTABLE_ENDPOINT']
PAGES = ('index',)
def render(context):
env = Environment(loader=FileSystemLoader('./templates'))
for name in PAGES:
basename = name + '.html'
page = frontmatter.load(os.path.join('templates', basename))
template = env.from_string(page.content)
with open(basename, 'wb') as f:
page_context = {}
page_context.update(**context)
page_context.update(**page.metadata)
f.write(template.render(**page_context).encode('utf-8'))
print 'Wrote {}'.format(basename)
def get_speakers():
resp = requests.get(
AIRTABLE_ENDPOINT + '/Speakers',
params={'maxRecords': 100,
'view': 'Main View'},
headers={'Authorization': 'Bearer ' + AIRTABLE_API_KEY})
for speaker in resp.json()['records']:
yield speaker['fields']
def get_time_range(day):
start = arrow.get(datetime(2017, 2, day, 8), 'Asia/Manila')
end = arrow.get(datetime(2017, 2, day, 19), 'Asia/Manila')
for r in arrow.Arrow.span_range('hour', start, end, tz='Asia/Manila'):
yield r[0].isoformat()
if r[0] < end:
yield r[0].replace(minutes=+30).isoformat()
def get_schedule(view):
resp = requests.get(
AIRTABLE_ENDPOINT + '/Schedule',
params={'maxRecords': 100,
'view': view},
headers={'Authorization': 'Bearer ' + AIRTABLE_API_KEY})
activities = OrderedDict()
for record in resp.json()['records']:
fields = record['fields']
activity = activities.setdefault(fields['Activity'], [])
start = arrow.get(fields['Start']).to('Asia/Manila')
end = arrow.get(fields['End']).to('Asia/Manila')
activity.append({
'start': start.isoformat(),
'end': end.isoformat(),
'topic': fields['Topic'],
'description': fields.get('Description'),
})
return activities
if __name__ == '__main__':
context = {
'speakers': get_speakers(),
'time_range_day_1': list(get_time_range(25)),
'time_range_day_2': list(get_time_range(26)),
'schedule_day_1': get_schedule('Day 1'),
'schedule_day_2': get_schedule('Day 2'),
}
render(context)