From 93d4213f0c893917224e0304f53c96509d75dd0b Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 12 Jul 2024 19:35:29 +0200 Subject: [PATCH] fix: assume RaBe time for archiv requests --- cridlib/strategy/past.py | 6 ++++++ tests/test_get.py | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cridlib/strategy/past.py b/cridlib/strategy/past.py index 8d962d5..1642808 100644 --- a/cridlib/strategy/past.py +++ b/cridlib/strategy/past.py @@ -2,9 +2,12 @@ from datetime import datetime +from pytz import timezone + from cridlib.util import get_session __ARCHIV_BROADCASTS_URL = "https://archiv.rabe.ch/api/broadcasts/" +__ARCHIV_TIMEZONE = "Europe/Zurich" def get_show(past: datetime) -> str: @@ -21,6 +24,9 @@ def get_show(past: datetime) -> str: Show name from the archive for `past`. """ + if past.tzname != __ARCHIV_TIMEZONE: + past = past.astimezone(timezone(__ARCHIV_TIMEZONE)) + _url = f"{__ARCHIV_BROADCASTS_URL}{past.year}/{past.month:02d}/{past.day:02d}/{past.hour:02d}{past.minute:02d}{past.second:02d}" # noqa: E501 _resp = get_session().get(_url, timeout=10) _json = _resp.json() diff --git a/tests/test_get.py b/tests/test_get.py index 9649c2c..aed3533 100644 --- a/tests/test_get.py +++ b/tests/test_get.py @@ -18,21 +18,21 @@ def test_get_past(archiv_mock): # noqa: ARG001 """Test meth:`get` for past shows.""" with freeze_time("1993-03-02 00:00:00 UTC"): crid = cridlib.get( - timestamp=datetime(1993, 3, 1, 13, 12, 00, tzinfo=timezone.utc), + timestamp=datetime(1993, 3, 1, 12, 12, 00, tzinfo=timezone.utc), ) assert crid.version == "v1" assert crid.show == "test" - assert str(crid) == "crid://rabe.ch/v1/test#t=clock=19930301T131200.00Z" + assert str(crid) == "crid://rabe.ch/v1/test#t=clock=19930301T121200.00Z" # show with additional local args in fragments with freeze_time("1993-03-02 00:00:00 UTC"): crid = cridlib.get( - timestamp=datetime(1993, 3, 1, 13, 12, 00, tzinfo=timezone.utc), + timestamp=datetime(1993, 3, 1, 12, 12, 00, tzinfo=timezone.utc), fragment="myid=1234", ) assert crid.version == "v1" assert crid.show == "test" - assert str(crid) == "crid://rabe.ch/v1/test#t=clock=19930301T131200.00Z&myid=1234" + assert str(crid) == "crid://rabe.ch/v1/test#t=clock=19930301T121200.00Z&myid=1234" def test_get_future(libretime_mock): # noqa: ARG001