|
| 1 | +import json |
| 2 | +import requests |
| 3 | + |
| 4 | +# Configuration variables: |
| 5 | +# This URL can be a custom URL or pretalx.com/ one depending on the event configuration |
| 6 | +CONFERENCE_URL = "https://programme.europython.eu/api/events/europython-2025" |
| 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 | + |
| 10 | + |
| 11 | +def get_pretalx_submission_types(): |
| 12 | + url = f"{CONFERENCE_URL}/submission-types" |
| 13 | + submission_types = {} |
| 14 | + |
| 15 | + while url: |
| 16 | + try: |
| 17 | + response = requests.get(url, headers={"Authorization": TOKEN}) |
| 18 | + data = response.json() |
| 19 | + |
| 20 | + for stype in data["results"]: |
| 21 | + if stype["id"] not in submission_types: |
| 22 | + submission_types[stype["id"]] = stype["name"] |
| 23 | + |
| 24 | + url = data.get("next") |
| 25 | + |
| 26 | + except requests.exceptions.RequestException as e: |
| 27 | + print(f"Error fetching submission types: {e}") |
| 28 | + return None |
| 29 | + |
| 30 | + return submission_types |
| 31 | + |
| 32 | + |
| 33 | +def get_pretalx_submissions(all_speakers): |
| 34 | + url = f"{CONFERENCE_URL}/submissions" |
| 35 | + confirmed_submissions = {} |
| 36 | + |
| 37 | + submissions_types = get_pretalx_submission_types() |
| 38 | + |
| 39 | + while url: |
| 40 | + try: |
| 41 | + response = requests.get(url, headers={"Authorization": TOKEN}) |
| 42 | + |
| 43 | + data = response.json() |
| 44 | + |
| 45 | + for submission in data["results"]: |
| 46 | + |
| 47 | + if submission["state"] == "confirmed": |
| 48 | + |
| 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 |
| 61 | + |
| 62 | + for speaker_code in submission["speakers"]: |
| 63 | + |
| 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 | + } |
| 70 | + |
| 71 | + url = data.get("next") |
| 72 | + |
| 73 | + except requests.exceptions.RequestException as e: |
| 74 | + print(f"Error fetching submissions: {e}") |
| 75 | + return None |
| 76 | + |
| 77 | + return confirmed_submissions |
| 78 | + |
| 79 | + |
| 80 | +def get_pretalx_speakers(): |
| 81 | + url = f"{CONFERENCE_URL}/speakers" |
| 82 | + speakers = {} |
| 83 | + |
| 84 | + while url: |
| 85 | + try: |
| 86 | + response = requests.get(url, headers={"Authorization": TOKEN}) |
| 87 | + data = response.json() |
| 88 | + |
| 89 | + for speaker in data["results"]: |
| 90 | + code = speaker["code"] |
| 91 | + if code not in speakers: |
| 92 | + speakers[code] = speaker["name"] |
| 93 | + |
| 94 | + url = data.get("next") |
| 95 | + |
| 96 | + except requests.exceptions.RequestException as e: |
| 97 | + print(f"Error fetching speakers: {e}") |
| 98 | + return None |
| 99 | + |
| 100 | + return speakers |
| 101 | + |
| 102 | + |
| 103 | +if __name__ == "__main__": |
| 104 | + speakers = get_pretalx_speakers() |
| 105 | + |
| 106 | + data = get_pretalx_submissions(speakers) |
| 107 | + d = {} |
| 108 | + |
| 109 | + if data: |
| 110 | + |
| 111 | + d["year"] = YEAR |
| 112 | + d["speakers"] = [] |
| 113 | + for _, entry in data.items(): |
| 114 | + d["speakers"].append( |
| 115 | + { |
| 116 | + "fullname": entry["fullname"], |
| 117 | + "type": entry["type"], |
| 118 | + "title": entry["title"], |
| 119 | + "level": "", # TODO: each conference will have this as a custom question |
| 120 | + } |
| 121 | + ) |
| 122 | + |
| 123 | + print(json.dumps(d, indent=4)) |
| 124 | + |
| 125 | + else: |
| 126 | + print("Failed to fetch speakers data") |
0 commit comments