add option to parse voc-schema compatible json schedule

This commit is contained in:
Franzi 2023-12-18 06:52:01 +01:00
parent bceab0ebfd
commit 11751552e9
2 changed files with 101 additions and 48 deletions

View file

@ -28,8 +28,19 @@
"title": "Schedule", "title": "Schedule",
"type": "section" "type": "section"
}, { }, {
"title": "Event URL", "title": "JSON flavour",
"name": "event_url", "ui_width": 12,
"name": "json_flavour",
"type": "select",
"default": "pretalx-broadcast-tools",
"options": [
["pretalx-broadcast-tools", "pretalx-broadcast-tools (input event URL below)"],
["voc-schema", "C3VOC JSON schema compatible (input JSON URL below)"]
]
}, {
"title": "Schedule URL",
"ui_width": 12,
"name": "schedule_url",
"type": "string", "type": "string",
"default": "https://pretalx.example.com/my-super-cool-event/" "default": "https://pretalx.example.com/my-super-cool-event/"
}, { }, {

134
service
View file

@ -51,57 +51,99 @@ def main():
event_tz = pytz.utc event_tz = pytz.utc
while True: while True:
event_url = config["event_url"] schedule_url = config["schedule_url"]
if not event_url.endswith("/"): if "example.com" in schedule_url:
event_url = event_url + "/" log("default schedule url, waiting for config update")
if "example.com" in event_url:
log("default event url, waiting for config update")
# sleep forever, service will get restarted if the config # sleep forever, service will get restarted if the config
# changes. # changes.
time.sleep(99999999) time.sleep(99999999)
log("event url: {}".format(schedule_url))
log("event url: {}".format(event_url)) if config['json_flavour'] == 'pretalx-broadcast-tools':
if not schedule_url.endswith("/"):
try: schedule_url = schedule_url + "/"
r = get( try:
event_url + "p/broadcast-tools/event.json", r = get(
) schedule_url + "p/broadcast-tools/event.json",
r.raise_for_status()
except Exception as e:
log("updating event info failed: {}".format(repr(e)))
# Only print the error message. If we have fetched the event
# info json blob atleast once, we have all the information
# we need.
else:
event_info = r.json()
node.write_json("event.json", event_info)
log("updated event info json")
if event_info is not None:
event_start = datetime.strptime(event_info["start"], "%Y-%m-%d")
event_tz = pytz.timezone(event_info["timezone"])
try:
r = get(
event_url + "p/broadcast-tools/schedule.json",
)
r.raise_for_status()
except Exception as e:
log("updating schedule failed: {}".format(repr(e)))
# Only print the error message. If we have fetched the schedule
# info json blob atleast once, we have all the information
# we need.
else:
schedule = r.json()
for talk in schedule["talks"]:
talk["start_str"] = (
datetime.fromtimestamp(talk["start_ts"])
.replace(tzinfo=pytz.utc)
.astimezone(event_tz)
.strftime("%H:%M")
) )
node.write_json("schedule.json", schedule) r.raise_for_status()
log("updated schedule json") except Exception as e:
log("updating event info failed: {}".format(repr(e)))
# Only print the error message. If we have fetched the event
# info json blob atleast once, we have all the information
# we need.
else:
event_info = r.json()
if event_info is not None:
event_start = datetime.strptime(event_info["start"], "%Y-%m-%d")
event_tz = pytz.timezone(event_info["timezone"])
try:
r = get(
schedule_url + "p/broadcast-tools/schedule.json",
)
r.raise_for_status()
except Exception as e:
log("updating schedule failed: {}".format(repr(e)))
# Only print the error message. If we have fetched the schedule
# info json blob atleast once, we have all the information
# we need.
else:
schedule = r.json()
for talk in schedule["talks"]:
talk["start_str"] = (
datetime.fromtimestamp(talk["start_ts"])
.replace(tzinfo=pytz.utc)
.astimezone(event_tz)
.strftime("%H:%M")
)
node.write_json("schedule.json", schedule)
log("updated schedule json")
elif config['json_flavour'] == 'voc-schema':
try:
r = get(schedule_url)
r.raise_for_status()
except Exception as e:
log("getting schedule.json failed: {}".format(repr(e)))
else:
raw_schedule = r.json()
schedule = {'talks': []}
event_start = datetime.strptime(raw_schedule["conference"]["start"][:10], "%Y-%m-%d")
event_tz = pytz.timezone(raw_schedule["conference"]["time_zone_name"])
for day in raw_schedule["days"]:
for room in day["rooms"].values():
for talk in room:
start = datetime.strptime(talk["date"][:19], "%Y-%m-%dT%H:%M%:S").replace(tzinfo=event_tz)
d_h, d_m = talk["duration"].split(":")
end = start + timedelta(hours=int(d_h), minutes=int(d_m))
talk["start_ts"] = start.timestamp()
talk["start_str"] = talk["start"]
talk["end_ts"] = end.timestamp()
talk["locale"] = talk["language"]
track = None
if talk["track"]:
for t in raw_schedule["conference"]["tracks"]:
if t["name"] == talk["track"]:
track = {
"color": t["color"],
"name": t["name"],
}
break
talk["track"] = track
persons = []
for p in talk["persons"]:
persons.append(p["public_name"])
talk["persons"] = persons
schedule["talks"].append(talk)
node.write_json("schedule.json", schedule)
log("updated schedule json")
idle(30, event_start, event_tz) idle(30, event_start, event_tz)