10
10
sys .path .insert (1 , '../_ext' )
11
11
12
12
import os
13
- from collections import OrderedDict
13
+ from collections import OrderedDict , defaultdict
14
14
from utils import slugify
15
15
import requests
16
16
from ruamel import yaml
@@ -36,18 +36,19 @@ def convert_to_yaml(year, series, series_slug, yaml_output, pretalx_slug):
36
36
print ('Error: PRETALX_TOKEN not found in environment variables.' )
37
37
return
38
38
http_headers = {'Authorization' : 'Token ' + os .environ ['PRETALX_TOKEN' ]}
39
- submissions_url = f'https://pretalx.com/api/events/{ pretalx_slug } /submissions/?state=confirmed'
39
+ submissions_url = f'https://pretalx.com/api/events/{ pretalx_slug } /submissions/?state=confirmed&expand=speakers '
40
40
print (f'Loading submissions from { submissions_url } ...' )
41
41
submissions = requests .get (submissions_url , headers = http_headers )
42
42
if submissions .status_code != 200 :
43
43
print (f'Error: submissions request failed: { submissions .status_code } : { submissions .text } ' )
44
44
return
45
45
46
+ answers = get_answers (pretalx_slug , http_headers )
46
47
for index , talk in enumerate (submissions .json ()['results' ]):
47
48
slug = slugify (talk ['title' ][:MAX_TITLE_LENGTH_FOR_SLUG ] + '-' + talk ['speakers' ][0 ]['name' ])
48
49
print (f'Processing talk { slug } ...' )
49
50
50
- speaker_info = retrieve_speaker_info ([s ['code' ] for s in talk ['speakers' ]], http_headers , pretalx_slug )
51
+ speaker_info = retrieve_speaker_info ([s ['code' ] for s in talk ['speakers' ]], http_headers , pretalx_slug , answers )
51
52
if not speaker_info :
52
53
print (f'Error: failed to retrieve info for speaker s["code"]' )
53
54
return
@@ -71,7 +72,7 @@ def convert_to_yaml(year, series, series_slug, yaml_output, pretalx_slug):
71
72
print ('Completed!' )
72
73
73
74
74
- def retrieve_speaker_info (speaker_codes , http_headers , pretalx_slug ):
75
+ def retrieve_speaker_info (speaker_codes , http_headers , pretalx_slug , answers ):
75
76
result = []
76
77
for speaker_code in speaker_codes :
77
78
speaker_url = f'https://pretalx.com/api/events/{ pretalx_slug } /speakers/{ speaker_code } /'
@@ -82,15 +83,15 @@ def retrieve_speaker_info(speaker_codes, http_headers, pretalx_slug):
82
83
return
83
84
84
85
def search_answers (speaker_dict , search_string ):
85
- for answer in speaker_dict [ ' answers' ] :
86
- if search_string in answer [ ' question' ][ 'question' ][ 'en' ] .lower ():
87
- return answer [ 'answer' ]
86
+ for question , answer in answers . get ( speaker_code , []) :
87
+ if search_string in question .lower ():
88
+ return answer
88
89
89
90
speaker = speaker_response .json ()
90
91
speaker_slug = slugify (speaker ['name' ])
91
92
92
- if speaker ['avatar ' ]:
93
- image_response = requests .get (speaker ['avatar ' ], stream = True )
93
+ if speaker ['avatar_url ' ]:
94
+ image_response = requests .get (speaker ['avatar_url ' ], stream = True )
94
95
avatar_path = SPEAKER_IMAGE_PATH + speaker_slug + '.' + CONTENT_TYPE_EXTENSIONS [image_response .headers ['content-type' ]]
95
96
if image_response .status_code != 200 :
96
97
print (f'Error: speaker avatar request failed: { image_response .status_code } : { image_response .text } ' )
@@ -108,9 +109,36 @@ def search_answers(speaker_dict, search_string):
108
109
]))
109
110
return result
110
111
112
+
113
+ def get_answers (pretalx_slug , http_headers ):
114
+ url = f'https://pretalx.com/api/events/{ pretalx_slug } /answers/?expand=question'
115
+ print (f'Loading answers from { url } ...' )
116
+ answers = load_pretalx_resource (url , http_headers )
117
+ result = defaultdict (list )
118
+ for answer in answers :
119
+ result [answer ['person' ]].append ((answer ['question' ]['question' ]['en' ], answer ['answer' ]))
120
+ return result
121
+
122
+ def load_pretalx_resource (url , http_headers ):
123
+ results = []
124
+ while url :
125
+ response = requests .get (url , headers = http_headers )
126
+ # 403 may occur as a pretalx bug
127
+ if response .status_code not in [200 , 403 ]:
128
+ print (f'Error: request failed: { response .status_code } : { response .text } ' )
129
+ return
130
+
131
+ results += response .json ()['results' ]
132
+
133
+ if response .json ()['next' ]:
134
+ url = response .json ()['next' ]
135
+ else :
136
+ break
137
+ return results
138
+
111
139
if __name__ == '__main__' :
112
140
year = '2025'
113
- place = "Portland "
141
+ place = "Berlin "
114
142
convert_to_yaml (
115
143
year ,
116
144
series = 'Write the Docs ' + place ,
0 commit comments