Skip to content

Commit

Permalink
Merge pull request #256 from ArtrenH/main
Browse files Browse the repository at this point in the history
223-11-28-03
  • Loading branch information
Belissimo-T authored Nov 28, 2023
2 parents 496b721 + 479ddb6 commit 4e27a24
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
19 changes: 7 additions & 12 deletions backend/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class PlanDownload(Event):
date: datetime.date
last_modified: datetime.datetime
file_length: int
proxies_used: int | None = None


@dataclasses.dataclass
Expand Down Expand Up @@ -103,10 +104,8 @@ def _submit_event(event: Event):
event_base_dict = event.get_base_dict()

out = {}
# noinspection PyDataclass
for key, value in dataclasses.asdict(event).items():
if key in event_base_dict:
continue

if isinstance(value, (datetime.datetime, datetime.date)):
out[key] = value.isoformat()
else:
Expand Down Expand Up @@ -144,17 +143,13 @@ def iterate_events(type_: typing.Type[_T2], school_number: str | None = None) ->
for event in cursor:
obj = type_.__new__(type_)

for field in dataclasses.fields(obj):
if field.name in event:
continue
obj.__dict__ = event["data"]

for field in dataclasses.fields(obj):
if field.type is datetime.datetime:
obj.__dict__[field.name] = datetime.datetime.fromisoformat(event["data"][field.name])
else:
try:
obj.__dict__[field.name] = event["data"][field.name]
except KeyError:
pass
obj.__dict__[field.name] = datetime.datetime.fromisoformat(obj.__dict__[field.name])
elif field.type is datetime.date:
obj.__dict__[field.name] = datetime.date.fromisoformat(obj.__dict__[field.name])

obj.__dict__["school_number"] = event["school_number"]
obj.__dict__["start_time"] = datetime.datetime.fromisoformat(event["start_time"])
Expand Down
4 changes: 3 additions & 1 deletion backend/plan_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ async def download_indiware_mobil(
etag=plan_response.etag,
)

# noinspection PyUnresolvedReferences
timer.submit(plan_type=plan_filename, last_modified=plan_response.last_modified,
file_length=len(plan_response.content), date=date)
file_length=len(plan_response.content), date=date,
proxies_used=plan_response.response._num_proxy_tries)

self.cache.store_plan_file(date, revision, plan_response.content, plan_filename)
self.cache.store_plan_file(date, revision, json.dumps(downloaded_file.serialize()),
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Flask-WTF~=1.1.1
Flask-Compress~=1.13
pymongo~=4.3.3
python-dotenv~=1.0.0
bumstundenplan24-wrapper@ git+https://github.com/Belissimo-T/stundenplan24-wrapper@2ea93550
bumstundenplan24-wrapper@ git+https://github.com/Belissimo-T/stundenplan24-wrapper@da592cb4
Werkzeug~=2.3.6
discord-webhook~=1.3.0
brotlicffi~=1.1.0.0
Expand Down

0 comments on commit 4e27a24

Please sign in to comment.