1
1
import json
2
+ import sys
3
+ import argparse
4
+ from typing import Any
5
+ from datetime import datetime
6
+
2
7
import requests
3
8
4
- # Configuration variables:
5
- # This URL can be a custom URL or pretalx.com/ one depending on the event configuration
6
- CONFERENCE_URL = ""
7
- TOKEN = "" # Not necessary, but in case of private events it's required
8
- YEAR = 2025 # Some events will not have it in the URL so we do it manually
9
9
10
+ def get_response_data_from_url (url : str ) -> dict [str , Any ]:
11
+ try :
12
+ response = requests .get (url , headers = {"Authorization" : TOKEN })
13
+ data = response .json ()
14
+ except requests .exceptions .RequestException as e :
15
+ print (f"Error fetching data: { e } " )
16
+ sys .exit (1 )
10
17
11
- def get_pretalx_submission_types ():
12
- url = f"{ CONFERENCE_URL } /submission-types"
13
- submission_types = {}
18
+ return data
14
19
15
- while url :
16
- try :
17
- response = requests .get (url , headers = {"Authorization" : TOKEN })
18
- data = response .json ()
19
20
20
- for stype in data ["results" ]:
21
- if stype ["id" ] not in submission_types :
22
- submission_types [stype ["id" ]] = stype ["name" ]
21
+ def get_pretalx_submission_types (conference_url : str ) -> dict [str , str ]:
22
+ url : str | None = f"{ conference_url } /submission-types"
23
+ submission_types : dict [str , str ] = {}
24
+
25
+ while url :
26
+ data : dict [str , Any ] = get_response_data_from_url (url )
23
27
24
- url = data .get ("next" )
28
+ for stype in data ["results" ]:
29
+ if stype ["id" ] not in submission_types :
30
+ submission_types [stype ["id" ]] = stype ["name" ]
25
31
26
- except requests .exceptions .RequestException as e :
27
- print (f"Error fetching submission types: { e } " )
28
- return None
32
+ url = data .get ("next" )
29
33
30
34
return submission_types
31
35
32
36
33
- def get_pretalx_submissions (all_speakers ) :
34
- url = f"{ CONFERENCE_URL } /submissions"
37
+ def get_pretalx_submissions (conference_url : str , all_speakers : dict [ str , str ]) -> dict [ str , dict ] :
38
+ url : str | None = f"{ conference_url } /submissions"
35
39
confirmed_submissions = {}
36
40
37
- submissions_types = get_pretalx_submission_types ()
41
+ submissions_types = get_pretalx_submission_types (conference_url )
38
42
39
43
while url :
40
- try :
41
- response = requests .get (url , headers = {"Authorization" : TOKEN })
42
-
43
- data = response .json ()
44
-
45
- for submission in data ["results" ]:
44
+ data : dict [str , Any ] = get_response_data_from_url (url )
46
45
47
- if submission [ "state" ] == "confirmed" :
46
+ for submission in data [ "results" ] :
48
47
49
- submission_code = submission ["code" ]
50
- submission_speakers = submission ["speakers" ]
51
- submission_type = submissions_types [submission ["submission_type" ]]
52
- if isinstance (submission_type , dict ):
53
- try :
54
- # Search for 'en' default language
55
- # otherwise, the first one
56
- submission_type = submission_type ["en" ]
57
- except KeyError :
58
- for k , v in submission_type .items ():
59
- submission_type = v
60
- break
48
+ if submission ["state" ] == "confirmed" :
61
49
62
- for speaker_code in submission ["speakers" ]:
50
+ submission_code = submission ["code" ]
51
+ submission_speakers = submission ["speakers" ]
52
+ submission_type = submissions_types [submission ["submission_type" ]]
53
+ if isinstance (submission_type , dict ):
54
+ try :
55
+ # Search for 'en' default language
56
+ # otherwise, the first one
57
+ submission_type = submission_type ["en" ]
58
+ except KeyError :
59
+ for k , v in submission_type .items ():
60
+ submission_type = v
61
+ break
63
62
64
- speaker_name = all_speakers [speaker_code ]
65
- confirmed_submissions [f"{ submission_code } -{ speaker_code } " ] = {
66
- "fullname" : speaker_name ,
67
- "title" : submission ["title" ],
68
- "type" : submission_type ,
69
- }
63
+ for speaker_code in submission_speakers :
70
64
71
- url = data .get ("next" )
65
+ speaker_name = all_speakers [speaker_code ]
66
+ confirmed_submissions [f"{ submission_code } -{ speaker_code } " ] = {
67
+ "fullname" : speaker_name ,
68
+ "title" : submission ["title" ],
69
+ "type" : submission_type ,
70
+ }
72
71
73
- except requests .exceptions .RequestException as e :
74
- print (f"Error fetching submissions: { e } " )
75
- return None
72
+ url = data .get ("next" )
76
73
77
74
return confirmed_submissions
78
75
79
76
80
- def get_pretalx_speakers () :
81
- url = f"{ CONFERENCE_URL } /speakers"
77
+ def get_pretalx_speakers (conference_url : str ) -> dict [ str , str ] :
78
+ url : str | None = f"{ conference_url } /speakers"
82
79
speakers = {}
83
80
84
81
while url :
85
- try :
86
- response = requests .get (url , headers = {"Authorization" : TOKEN })
87
- data = response .json ()
82
+ data : dict [str , Any ] = get_response_data_from_url (url )
88
83
89
- for speaker in data ["results" ]:
90
- code = speaker ["code" ]
91
- if code not in speakers :
92
- speakers [code ] = speaker ["name" ]
84
+ for speaker in data ["results" ]:
85
+ code = speaker ["code" ]
86
+ if code not in speakers :
87
+ speakers [code ] = speaker ["name" ]
93
88
94
- url = data .get ("next" )
95
-
96
- except requests .exceptions .RequestException as e :
97
- print (f"Error fetching speakers: { e } " )
98
- return None
89
+ url = data .get ("next" )
99
90
100
91
return speakers
101
92
102
93
103
- if __name__ == "__main__" :
104
- speakers = get_pretalx_speakers ()
94
+ def get_event_year (conference_url : str ) -> int :
95
+ data : dict [str , Any ] = get_response_data_from_url (conference_url )
96
+ date = data ["date_from" ]
97
+ year : int = 2025
98
+ try :
99
+ date_from = datetime .strptime (date , "%Y-%m-%d" )
100
+ except ValueError :
101
+ print (f"Error: couldn't parse date '{ date } '. Falling back to 2025" )
102
+ return year
103
+
104
+ return date_from .year
105
105
106
- submission_data = get_pretalx_submissions (speakers )
107
- data = {}
106
+
107
+ if __name__ == "__main__" :
108
+ # This URL can be a custom URL or pretalx.com/ one depending on the event configuration
109
+ CONFERENCE_URL = ""
110
+ TOKEN = "" # Not necessary, but in case of private events it's required
111
+
112
+ parser = argparse .ArgumentParser ()
113
+ parser .add_argument ('--url' )
114
+ parser .add_argument ('--output' )
115
+ args = parser .parse_args ()
116
+
117
+ # Check command-line arguments
118
+ if args .url is not None :
119
+ if CONFERENCE_URL :
120
+ print (f"-- WARNING: Overriding url '{ CONFERENCE_URL } ' "
121
+ f"with command line value '{ args .url } '" )
122
+ print (f"-- Using event url: '{ args .url } '" )
123
+ CONFERENCE_URL = args .url
124
+
125
+ if args .output is not None :
126
+ if not args .output .endswith (".json" ):
127
+ print (f"ERROR: file '{ args .output } ' is not a JSON file" )
128
+ sys .exit (1 )
129
+
130
+ year = get_event_year (CONFERENCE_URL )
131
+ speakers = get_pretalx_speakers (CONFERENCE_URL )
132
+ submission_data = get_pretalx_submissions (CONFERENCE_URL , speakers )
133
+
134
+ data : dict [str , Any ] = {}
108
135
109
136
if submission_data :
110
137
111
- data ["year" ] = YEAR
138
+ data ["year" ] = year
112
139
data ["speakers" ] = []
113
140
for _ , entry in submission_data .items ():
114
141
data ["speakers" ].append (
@@ -119,7 +146,11 @@ def get_pretalx_speakers():
119
146
}
120
147
)
121
148
122
- print (json .dumps (data , indent = 4 ))
123
-
149
+ if args .output is not None :
150
+ with open (args .output , "w" ) as f :
151
+ json .dump (data , f , ensure_ascii = False , indent = 4 )
152
+ print (f"-- Written file: '{ args .output } '" )
153
+ else :
154
+ print (json .dumps (data , indent = 4 ))
124
155
else :
125
156
print ("Failed to fetch speakers data" )
0 commit comments