-
Notifications
You must be signed in to change notification settings - Fork 3
/
gen_event_config.py
executable file
·63 lines (48 loc) · 1.86 KB
/
gen_event_config.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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import sys
import argparse
import requests
import jinja2
# request currently active conferences from streams API
r = requests.get('https://streaming.media.ccc.de/streams/v2.json?forceopen=yess')
#r = requests.get('http://localhost:8000/streams/v2.json')
if r.status_code != 200:
print("Fetching streams API failed with response: ", r, r.text)
exit(1)
conferences = r.json()
# list available conferences when argument is missing
if len(sys.argv) <= 1:
print("Streams API currenly lists following conferences:")
for c in conferences:
print(" - {}".format(c['slug']))
print()
parser = argparse.ArgumentParser()
parser.add_argument('slug', help="slug aka acronym of a confernce currenly active at streaming website")
args = parser.parse_args()
# filter for our conferences specified by argument
conference = None
for c in conferences:
if c['slug'] == args.slug:
conference = c
break
if conference is None:
print("Error – unknown conference: " + args.slug)
exit(1)
#print(conference)
if 'schedule' not in conference or conference['schedule'] is None:
print("Warning: Schedule URL is empty!");
# generate config and write it to a file
templateLoader = jinja2.FileSystemLoader(searchpath="configs")
templateEnv = jinja2.Environment(loader=templateLoader)
template = templateEnv.get_template("cfg.example.j2")
output = template.render( conference )
config_file = 'configs/' + args.slug
with open(config_file, 'w') as f:
f.write(output)
print("The new config was successfully written to " + config_file)
print("Next:")
print(" - check config and apply manual adjustments")
print(" - after a minute, a cronjob will run and download the schedule")
# TODO?: run scripts/get-fahrplan.sh from this script?
print(" - then start the scheduler (run as user relive): ./launcher.sh " + args.slug)