|
1 | | -import sys |
| 1 | +from argparse import ArgumentParser |
2 | 2 |
|
3 | 3 | from src.config import Config |
4 | 4 | from src.utils.parse import Parse |
|
7 | 7 | from src.utils.utils import Utils |
8 | 8 |
|
9 | 9 | if __name__ == "__main__": |
10 | | - print(f"Parsing the data from {Config.raw_path}...") |
| 10 | + parser = ArgumentParser(description="Transform data from Pretalx to EuroPython format and save it.") |
| 11 | + parser.add_argument( |
| 12 | + "-w", |
| 13 | + "--warn-dupes", |
| 14 | + action="store_true", |
| 15 | + help="Warn about duplicates in the data.", |
| 16 | + ) |
| 17 | + parser.add_argument( |
| 18 | + "-e", |
| 19 | + "--exclude", |
| 20 | + choices=["schedule", "youtube"], |
| 21 | + action="append", |
| 22 | + help="Exclude certain data from transformation.", |
| 23 | + ) |
| 24 | + args = parser.parse_args() |
| 25 | + exclude = set(args.exclude or []) |
| 26 | + |
| 27 | + |
| 28 | + print(f"Parsing submissions from {Config.raw_path}/submissions_latest.json...", end="") |
11 | 29 | pretalx_submissions = Parse.publishable_submissions( |
12 | 30 | Config.raw_path / "submissions_latest.json" |
13 | 31 | ) |
| 32 | + print(" done.") |
| 33 | + |
| 34 | + print(f"\nParsing speakers from {Config.raw_path}/speakers_latest.json...", end="") |
14 | 35 | pretalx_speakers = Parse.publishable_speakers( |
15 | 36 | Config.raw_path / "speakers_latest.json", pretalx_submissions.keys() |
16 | 37 | ) |
17 | | - pretalx_schedule = Parse.schedule(Config.raw_path / "schedule_latest.json") |
| 38 | + print(" done.") |
18 | 39 |
|
19 | | - # Parse the YouTube data |
20 | | - youtube_data = Parse.youtube(Config.raw_path / "youtube_latest.json") |
| 40 | + if "youtube" not in exclude: |
| 41 | + print(f"Parsing YouTube data from {Config.raw_path}/youtube_latest.json...", end="") |
| 42 | + youtube_data = Parse.youtube(Config.raw_path / "youtube_latest.json") |
| 43 | + print(" done.") |
| 44 | + else: |
| 45 | + youtube_data = {} |
21 | 46 |
|
22 | | - print("Computing timing relationships...") |
| 47 | + print("\nComputing timing relationships...", end="") |
23 | 48 | TimingRelationships.compute(pretalx_submissions.values()) |
| 49 | + print(" done.") |
24 | 50 |
|
25 | | - print("Transforming the data...") |
| 51 | + print("\nTransforming submissions...", end="") |
26 | 52 | ep_sessions = Transform.pretalx_submissions_to_europython_sessions( |
27 | 53 | pretalx_submissions, |
28 | 54 | youtube_data, |
29 | 55 | ) |
| 56 | + print(" done.") |
| 57 | + |
| 58 | + print("\nTransforming speakers...", end="") |
30 | 59 | ep_speakers = Transform.pretalx_speakers_to_europython_speakers(pretalx_speakers) |
31 | | - ep_schedule = Transform.pretalx_schedule_to_europython_schedule( |
32 | | - pretalx_schedule.breaks, ep_sessions, ep_speakers |
33 | | - ) |
| 60 | + print(" done.") |
34 | 61 |
|
35 | 62 | # Warn about duplicates if the flag is set |
36 | | - if len(sys.argv) > 1 and sys.argv[1] == "--warn-dupes": |
| 63 | + if args.warn_dupes: |
37 | 64 | Utils.warn_duplicates( |
38 | 65 | session_attributes_to_check=["title"], |
39 | 66 | speaker_attributes_to_check=["name"], |
40 | 67 | sessions_to_check=ep_sessions, |
41 | 68 | speakers_to_check=ep_speakers, |
42 | 69 | ) |
43 | 70 |
|
44 | | - print(f"Writing the data to {Config.public_path}...") |
| 71 | + print(f"\nWriting sessions to {Config.public_path}/sessions.json...", end="") |
45 | 72 | Utils.write_to_file(Config.public_path / "sessions.json", ep_sessions) |
| 73 | + print(" done.") |
| 74 | + |
| 75 | + print(f"\nWriting speakers to {Config.public_path}/speakers.json...", end="") |
46 | 76 | Utils.write_to_file(Config.public_path / "speakers.json", ep_speakers) |
47 | | - Utils.write_to_file( |
48 | | - Config.public_path / "schedule.json", ep_schedule, direct_dump=True |
49 | | - ) |
| 77 | + print(" done.") |
| 78 | + |
| 79 | + if "schedule" not in exclude: |
| 80 | + print("\nParsing schedule from {Config.raw_path}/schedule_latest.json...", end="") |
| 81 | + pretalx_schedule = Parse.schedule(Config.raw_path / "schedule_latest.json") |
| 82 | + print(" done.") |
| 83 | + |
| 84 | + print(f"\nTransforming the schedule...", end="") |
| 85 | + ep_schedule = Transform.pretalx_schedule_to_europython_schedule( |
| 86 | + pretalx_schedule.breaks, ep_sessions, ep_speakers |
| 87 | + ) |
| 88 | + print(" done.") |
| 89 | + |
| 90 | + print(f"\nWriting schedule to {Config.public_path}/schedule.json...", end="") |
| 91 | + Utils.write_to_file( |
| 92 | + Config.public_path / "schedule.json", ep_schedule, direct_dump=True |
| 93 | + ) |
| 94 | + print(" done.") |
0 commit comments