-
Notifications
You must be signed in to change notification settings - Fork 6
/
schedule.py
153 lines (133 loc) · 4.52 KB
/
schedule.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import json
from datetime import date, datetime, time
from pathlib import Path
from sys import exit
from urllib.request import Request, urlopen
# Constants, should be changed each year.
URL_BASE = "https://cfp.pycon.fr/api/events/pyconfr-2024/"
TALKS_URL = f"{URL_BASE}submissions/?limit=1000&questions=all"
ROOMS_URL = f"{URL_BASE}rooms/?limit=1000"
TOKEN_FILE = Path("token.key")
OUTPUT = Path("schedule.json")
if TOKEN_FILE.is_file():
TOKEN = TOKEN_FILE.read_text()
else:
print(f"ERROR: Please put your Pretalx token in the {TOKEN_FILE} file.")
exit()
SPRINT_DAYS = (
date(year=2024, month=10, day=31),
date(year=2024, month=11, day=1),
)
CONFERENCE_DAYS = (
date(year=2024, month=11, day=2),
date(year=2024, month=11, day=3),
)
DAY_START_TIME = time(hour=8, minute=30)
DAY_STOP_TIME = time(hour=18, minute=0)
SLOT_MINUTES = 30
EXTRA = {
"2024-11-02": {
"510": {
"id": "saturday-breakfast",
"title": {
"en": "Breakfast",
"fr": "Petit-déjeuner",
}
},
"750": {
"id": "saturday-lunch",
"title": {
"en": "Lunch",
"fr": "Déjeuner",
}
},
"960": {
"id": "saturday-snack",
"title": {
"en": "Snack Time",
"fr": "Goûter",
}
},
},
"2024-11-03": {
"510": {
"id": "sunday-breakfast",
"title": {
"en": "Breakfast",
"fr": "Petit-déjeuner",
}
},
"750": {
"id": "sunday-lunch",
"title": {
"en": "Lunch",
"fr": "Déjeuner",
}
},
},
}
# Define some util functions.
def to_minutes(time):
"""Get number of minutes in datetime.time."""
return time.hour * 60 + time.minute
def to_time(minutes):
"""Generate datetime.time containing given minutes."""
return time(hour=minutes//60, minute=minutes%60)
def clean_talk(talk):
"""Remove non-public data from talks"""
for speaker in talk["speakers"]:
del speaker["email"]
for key in ("do_not_record", "notes", "internal_notes"):
del talk[key]
# Check constants consistency.
assert DAY_START_TIME < DAY_STOP_TIME
assert to_minutes(DAY_START_TIME) % SLOT_MINUTES == 0
assert to_minutes(DAY_STOP_TIME) % SLOT_MINUTES == 0
# Download talks and rooms from API.
print("Downloading talks")
request = Request(TALKS_URL, headers={"Authorization": f"Token {TOKEN}"})
response = urlopen(request)
talks = tuple(talk for talk in json.loads(response.read())["results"] if talk["slot"])
print("Downloading rooms")
request = Request(ROOMS_URL, headers={"Authorization": f"Token {TOKEN}"})
response = urlopen(request)
rooms = sorted(json.loads(response.read())["results"], key=lambda room: room["position"])
rooms_dict = {room["id"]: room for room in rooms}
# Build table for conferences.
print("Generating schedule")
slots = range(to_minutes(DAY_START_TIME), to_minutes(DAY_STOP_TIME), SLOT_MINUTES)
hours = [to_time(minutes) for minutes in slots]
schedule = {day.isoformat(): {to_minutes(hour): {} for hour in hours} for day in CONFERENCE_DAYS}
sprints = {day.isoformat(): {to_minutes(hour): {} for hour in hours} for day in SPRINT_DAYS}
for talk in talks:
slot = talk["slot"]
# We assume that talks and schedule share the same timezone.
if not slot["start"]:
continue
start = datetime.fromisoformat(slot["start"])
end = datetime.fromisoformat(slot["end"])
clean_talk(talk)
slot_start_minutes = to_minutes(start) // SLOT_MINUTES * SLOT_MINUTES
slot_start = to_time(slot_start_minutes)
if start.date() in CONFERENCE_DAYS:
schedule[start.date().isoformat()][to_minutes(slot_start)][slot["room_id"]] = talk
rooms_dict[slot["room_id"]]["in_conferences"] = True
elif start.date() in SPRINT_DAYS:
sprints[start.date().isoformat()][to_minutes(slot_start)][slot["room_id"]] = talk
rooms_dict[slot["room_id"]]["in_sprints"] = True
else:
print("Wrong date for talk:", talk)
print(f"Writing schedule to {OUTPUT}")
OUTPUT.write_text(json.dumps({
"schedule": schedule,
"sprints": sprints,
"rooms": rooms,
"extra": EXTRA,
"speakers": {
speaker["code"]: speaker
for hours in schedule.values()
for rooms in hours.values()
for room in rooms.values()
for speaker in room["speakers"]
},
}).replace('http://cfp.pycon.fr/', 'https://cfp.pycon.fr/'))