-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparse.py
More file actions
74 lines (61 loc) · 2.44 KB
/
parse.py
File metadata and controls
74 lines (61 loc) · 2.44 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
import json
from collections.abc import KeysView
from pathlib import Path
from src.models.pretalx import PretalxSchedule, PretalxSpeaker, PretalxSubmission
from src.utils.utils import Utils
class Parse:
@staticmethod
def publishable_submissions(input_file: Path | str) -> dict[str, PretalxSubmission]:
"""
Returns only publishable submissions
"""
with open(input_file) as fd:
js = json.load(fd)
all_submissions = [PretalxSubmission.model_validate(s) for s in js]
publishable_submissions = [s for s in all_submissions if s.is_publishable]
publishable_submissions_by_code = {
s.code: s for s in publishable_submissions
}
return publishable_submissions_by_code
@staticmethod
def publishable_speakers(
input_file: Path | str,
publishable_sessions_keys: KeysView[str],
) -> dict[str, PretalxSpeaker]:
"""
Returns only speakers with publishable sessions
"""
with open(input_file) as fd:
js = json.load(fd)
all_speakers = [PretalxSpeaker.model_validate(s) for s in js]
speakers_with_publishable_sessions: list[PretalxSpeaker] = []
for speaker in all_speakers:
if publishable_sessions := Utils.publishable_sessions_of_speaker(
speaker, publishable_sessions_keys
):
speaker.submissions = sorted(publishable_sessions)
speakers_with_publishable_sessions.append(speaker)
publishable_speakers_by_code = {
s.code: s for s in speakers_with_publishable_sessions
}
return publishable_speakers_by_code
@staticmethod
def schedule(input_file: Path | str) -> PretalxSchedule:
"""
Returns the schedule:
PretalxSchedule.slots: list[PretalxSubmission]
PretalxSchedule.breaks: list[PretalxScheduleBreak]
"""
with open(input_file) as fd:
js = json.load(fd)
schedule = PretalxSchedule.model_validate(js)
return schedule
@staticmethod
def youtube(input_file: Path | str) -> dict[str, str]:
"""
Returns the Session code to YouTube URL mapping
"""
with open(input_file) as fd:
js = json.load(fd)
youtube_data = {s["submission"]: s["youtube_link"] for s in js}
return youtube_data