Skip to content

Commit 383c432

Browse files
authored
Fix up pretalx2cfpsheet for API and add remote/in-person flag (#2415)
* Fix up pretalx2cfpsheet for API and add remote/in-person flag * Fix tags
1 parent c8ecd0c commit 383c432

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

docs/_scripts/pretalx2cfpsheet.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ def get_review_scores(pretalx_slug, previous_slugs):
3737

3838
reviews_url = f'https://pretalx.com/api/events/{pretalx_slug}/reviews'
3939
reviews = load_pretalx_resource(reviews_url, http_headers)
40+
speaker_names = get_speaker_names(pretalx_slug, http_headers)
41+
submission_types = get_submission_types(pretalx_slug, http_headers)
42+
tags = get_tags(pretalx_slug, http_headers)
4043

4144
for review in reviews:
4245
try:
@@ -48,26 +51,27 @@ def get_review_scores(pretalx_slug, previous_slugs):
4851

4952
with open(output_file, 'w') as f:
5053
csvwriter = csv.writer(f)
51-
csvwriter.writerow(["Mean", "Median", "Pvar", "Title", "Speaker", "Tags", "Previous submissions", "URL"])
54+
csvwriter.writerow(["Mean", "Median", "Pvar", "Type", "Title", "Speaker", "Tags", "Previous submissions", "URL"])
5255
for code, submission in submissions.items():
5356
previous_for_speaker = {}
54-
for speaker in submission['speakers']:
55-
previous_for_speaker.update(previous_submissions.get(speaker['code'], {}))
57+
for speaker_slug in submission['speakers']:
58+
previous_for_speaker.update(previous_submissions.get(speaker_slug, {}))
5659
previous_for_speaker_str = '; '.join([
5760
f'{state.title()}: {", ".join(sorted(events))}'
5861
for state, events in
5962
sorted(previous_for_speaker.items())
6063
])
61-
speakers = ', '.join([speaker['name'] for speaker in submission['speakers']])
6264
url = f"https://pretalx.com/orga/event/{pretalx_slug}/submissions/{code}/reviews/"
6365
scores = submission.get('scores', [])
66+
speakers = ', '.join(speaker_names[speaker] for speaker in submission['speakers'])
6467
csvwriter.writerow([
6568
"%.1f" % statistics.mean(scores) if scores else '-',
6669
"%.1f" % statistics.median(scores) if scores else '-',
6770
"%.1f" % statistics.pvariance(scores) if scores else '-',
71+
submission_types[submission['submission_type']][0],
6872
submission['title'],
6973
speakers,
70-
', '.join(submission['tags']),
74+
', '.join([tags[t] for t in submission['tags']]),
7175
previous_for_speaker_str,
7276
url,
7377
])
@@ -94,17 +98,41 @@ def get_previous_submissions(pretalx_slugs, http_headers):
9498
for speaker in submission['speakers']:
9599
event_name = event['name']['en'].replace('Write the Docs', '').strip()
96100
state = submission['state']
97-
speakers_submissions.setdefault(speaker['code'], {}).setdefault(state, set()).add(event_name)
101+
speakers_submissions.setdefault(speaker, {}).setdefault(state, set()).add(event_name)
98102

99103
return speakers_submissions
100104

101105

102-
# Might be reusable in other pretalx interfaces
106+
def get_speaker_names(pretalx_slug, http_headers):
107+
url = f'https://pretalx.com/api/events/{pretalx_slug}/speakers/'
108+
print(f'Loading speaker names from {url}...')
109+
speaker_info = load_pretalx_resource(url, http_headers)
110+
return {
111+
s['code']: s['name'] for s in speaker_info
112+
}
113+
114+
def get_submission_types(pretalx_slug, http_headers):
115+
url = f'https://pretalx.com/api/events/{pretalx_slug}/submission-types/'
116+
print(f'Loading submission types names from {url}...')
117+
submission_types = load_pretalx_resource(url, http_headers)
118+
return {
119+
s['id']: s['name']['en'] for s in submission_types
120+
}
121+
122+
def get_tags(pretalx_slug, http_headers):
123+
url = f'https://pretalx.com/api/events/{pretalx_slug}/tags/'
124+
print(f'Loading tag names from {url}...')
125+
tags = load_pretalx_resource(url, http_headers)
126+
return {
127+
s['id']: s['tag'] for s in tags
128+
}
129+
103130
def load_pretalx_resource(url, http_headers):
104131
results = []
105132
while url:
106133
response = requests.get(url, headers=http_headers)
107-
if response.status_code != 200:
134+
# 403 may occur as a pretalx bug
135+
if response.status_code not in [200, 403]:
108136
print(f'Error: request failed: {response.status_code}: {response.text}')
109137
return
110138

@@ -119,7 +147,7 @@ def load_pretalx_resource(url, http_headers):
119147

120148
if __name__ == '__main__':
121149
get_review_scores(
122-
pretalx_slug='wtd-portland-2025',
150+
pretalx_slug='wtd-berlin-2025',
123151
previous_slugs=[
124152
'wtd-portland-2020',
125153
'wtd-prague-2020',
@@ -135,5 +163,6 @@ def load_pretalx_resource(url, http_headers):
135163
'wtd-portland-2024',
136164
'wtd-atlantic-2024',
137165
'wtd-australia-2024',
166+
'wtd-portland-2025',
138167
],
139168
)

0 commit comments

Comments
 (0)