mirror of
https://github.com/Kunsi/scheduled-plugin-pretalx-broadcast-tools.git
synced 2024-11-22 01:51:03 +00:00
add option to parse voc-schema compatible json schedule
This commit is contained in:
parent
bceab0ebfd
commit
11751552e9
2 changed files with 101 additions and 48 deletions
15
node.json
15
node.json
|
@ -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/"
|
||||||
}, {
|
}, {
|
||||||
|
|
64
service
64
service
|
@ -51,20 +51,20 @@ 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("/"):
|
||||||
|
schedule_url = schedule_url + "/"
|
||||||
try:
|
try:
|
||||||
r = get(
|
r = get(
|
||||||
event_url + "p/broadcast-tools/event.json",
|
schedule_url + "p/broadcast-tools/event.json",
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -74,8 +74,6 @@ def main():
|
||||||
# we need.
|
# we need.
|
||||||
else:
|
else:
|
||||||
event_info = r.json()
|
event_info = r.json()
|
||||||
node.write_json("event.json", event_info)
|
|
||||||
log("updated event info json")
|
|
||||||
|
|
||||||
if event_info is not None:
|
if event_info is not None:
|
||||||
event_start = datetime.strptime(event_info["start"], "%Y-%m-%d")
|
event_start = datetime.strptime(event_info["start"], "%Y-%m-%d")
|
||||||
|
@ -83,7 +81,7 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = get(
|
r = get(
|
||||||
event_url + "p/broadcast-tools/schedule.json",
|
schedule_url + "p/broadcast-tools/schedule.json",
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -102,6 +100,50 @@ def main():
|
||||||
)
|
)
|
||||||
node.write_json("schedule.json", schedule)
|
node.write_json("schedule.json", schedule)
|
||||||
log("updated schedule json")
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue