-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransform.py
More file actions
102 lines (88 loc) · 3.36 KB
/
transform.py
File metadata and controls
102 lines (88 loc) · 3.36 KB
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
from argparse import ArgumentParser
from src.config import Config
from src.utils.parse import Parse
from src.utils.timing_relationships import TimingRelationships
from src.utils.transform import Transform
from src.utils.utils import Utils
if __name__ == "__main__":
parser = ArgumentParser(
description="Transform data from Pretalx to EuroPython format and save it."
)
parser.add_argument(
"-w",
"--warn-dupes",
action="store_true",
help="Warn about duplicates in the data.",
)
parser.add_argument(
"-e",
"--exclude",
choices=["schedule", "youtube"],
action="append",
help="Exclude certain data from transformation.",
)
args = parser.parse_args()
exclude = set(args.exclude or [])
print(
f"Parsing submissions from {Config.raw_path}/submissions_latest.json...", end=""
)
pretalx_submissions = Parse.publishable_submissions(
Config.raw_path / "submissions_latest.json"
)
print(" done.")
print(f"\nParsing speakers from {Config.raw_path}/speakers_latest.json...", end="")
pretalx_speakers = Parse.publishable_speakers(
Config.raw_path / "speakers_latest.json", pretalx_submissions.keys()
)
print(" done.")
if "youtube" not in exclude:
print(
f"Parsing YouTube data from {Config.raw_path}/youtube_latest.json...",
end="",
)
youtube_data = Parse.youtube(Config.raw_path / "youtube_latest.json")
print(" done.")
else:
youtube_data = {}
print("\nComputing timing relationships...", end="")
TimingRelationships.compute(pretalx_submissions.values())
print(" done.")
print("\nTransforming submissions...", end="")
ep_sessions = Transform.pretalx_submissions_to_europython_sessions(
pretalx_submissions,
youtube_data,
)
print(" done.")
print("\nTransforming speakers...", end="")
ep_speakers = Transform.pretalx_speakers_to_europython_speakers(pretalx_speakers)
print(" done.")
# Warn about duplicates if the flag is set
if args.warn_dupes:
Utils.warn_duplicates(
session_attributes_to_check=["title"],
speaker_attributes_to_check=["name"],
sessions_to_check=ep_sessions,
speakers_to_check=ep_speakers,
)
print(f"\nWriting sessions to {Config.public_path}/sessions.json...", end="")
Utils.write_to_file(Config.public_path / "sessions.json", ep_sessions)
print(" done.")
print(f"\nWriting speakers to {Config.public_path}/speakers.json...", end="")
Utils.write_to_file(Config.public_path / "speakers.json", ep_speakers)
print(" done.")
if "schedule" not in exclude:
print(
"\nParsing schedule from {Config.raw_path}/schedule_latest.json...", end=""
)
pretalx_schedule = Parse.schedule(Config.raw_path / "schedule_latest.json")
print(" done.")
print(f"\nTransforming the schedule...", end="")
ep_schedule = Transform.pretalx_schedule_to_europython_schedule(
pretalx_schedule.breaks, ep_sessions, ep_speakers
)
print(" done.")
print(f"\nWriting schedule to {Config.public_path}/schedule.json...", end="")
Utils.write_to_file(
Config.public_path / "schedule.json", ep_schedule, direct_dump=True
)
print(" done.")