Skip to content

Commit 1b86147

Browse files
committed
Fix test, change path handling, turn config into a class
1 parent 713df1b commit 1b86147

File tree

10 files changed

+33
-28
lines changed

10 files changed

+33
-28
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ RUN pip install -r requirements.txt
88
COPY src/ ./src/
99
COPY Makefile .
1010

11-
RUN mkdir -p /srv/data/raw/europython-2024
12-
RUN mkdir -p /srv/data/public/2024/
11+
RUN mkdir -p /srv/data/raw/europython-2024/
12+
RUN mkdir -p /srv/data/public/europython-2024/
1313

1414

1515
CMD ["make", "all"]

data/public/2024/speakers.json

Whitespace-only changes.

src/config.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import os
2+
from pathlib import Path
23

3-
# with open("config.toml", "rb") as fd:
4-
# conf = tomllib.load(fd)
54

6-
conf = {
7-
"pretalx-token": os.environ["PRETALX_TOKEN"],
8-
}
5+
class Config:
6+
event = "europython-2024"
7+
project_root = Path(__file__).resolve().parents[1]
8+
raw_path = Path(f"{project_root}/data/raw/{event}")
9+
public_path = Path(f"{project_root}/data/public/{event}")
10+
11+
@staticmethod
12+
def token():
13+
return os.environ["PRETALX_TOKEN"]

src/config.toml.example

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/download.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import json
2-
from datetime import datetime
32
from pathlib import Path
4-
from pprint import pprint as pp
53

64
import requests
75

8-
from config import conf
9-
10-
11-
class Config:
12-
token = conf["pretalx-token"]
13-
event = "europython-2024"
6+
try:
7+
from config import Config
8+
except ImportError:
9+
from src.config import Config
1410

1511

1612
headers = {
@@ -44,7 +40,7 @@ class Config:
4440

4541
filename = resource.split("?")[0] # To get rid of "?questions"
4642
filename = f"{filename}_latest.json"
47-
filepath = f"../data/raw/{Config.event}/{filename}"
43+
filepath = Path.joinpath(Config.raw_path, filename)
4844

4945
with open(filepath, "w") as fd:
5046
json.dump(res0, fd)

src/transform.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import json
2-
import os
3-
from collections import defaultdict
4-
from datetime import date, datetime, time, timedelta
2+
from datetime import datetime
3+
from pathlib import Path
54

65
from pydantic import BaseModel, Field
76
from pydantic.class_validators import root_validator
87
from slugify import slugify
98

9+
try:
10+
from config import Config
11+
except ImportError:
12+
from src.config import Config
13+
1014

1115
class SpeakerQuestion:
1216
affiliation = "Company / Organization / Educational Institution"
@@ -171,7 +175,7 @@ def parse_submissions() -> list[PretalxSubmission]:
171175
"""
172176
Returns only confirmed talks
173177
"""
174-
with open("../data/raw/europython-2024/submissions_latest.json") as fd:
178+
with open(Path.joinpath(Config.raw_path, "submissions_latest.json")) as fd:
175179
js = json.load(fd)
176180
subs = []
177181
for item in js:
@@ -185,7 +189,7 @@ def parse_speakers() -> list[PretalxSpeaker]:
185189
"""
186190
Returns only speakers with confirmed talks
187191
"""
188-
with open("../data/raw/europython-2024/speakers_latest.json") as fd:
192+
with open(Path.joinpath(Config.raw_path, "speakers_latest.json")) as fd:
189193
js = json.load(fd)
190194
speakers = []
191195
for item in js:
@@ -213,7 +217,7 @@ def publishable_speakers(accepted_proposals: set[str]) -> dict[str, PretalxSpeak
213217

214218

215219
def save_publishable_sessions():
216-
path = "../data/public/2024/sessions.json"
220+
path = Path.joinpath(Config.public_path, "sessions.json")
217221

218222
publishable = publishable_submissions()
219223

@@ -223,7 +227,7 @@ def save_publishable_sessions():
223227

224228

225229
def save_publishable_speakers():
226-
path = "../data/public/2024/speakers.json"
230+
path = Path.joinpath(Config.public_path, "speakers.json")
227231

228232
publishable = publishable_submissions()
229233
speakers = publishable_speakers(publishable.keys())
@@ -237,6 +241,6 @@ def save_publishable_speakers():
237241
publishable_submissions()
238242
)
239243

240-
241-
save_publishable_sessions()
242-
save_publishable_speakers()
244+
if __name__ == "__main__":
245+
save_publishable_sessions()
246+
save_publishable_speakers()

tests/test_examples_are_up_to_date.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
2-
from transform import PretalxSubmission
2+
3+
from src.transform import PretalxSubmission
34

45
with open("./data/examples/pretalx/submissions.json") as fd:
56
pretalx_submissions = json.load(fd)

0 commit comments

Comments
 (0)