Skip to content

Commit a59a5dc

Browse files
committed
Hotfix: Handle missing livestream URLs
1 parent e29ca0d commit a59a5dc

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/europython_discord/program_notifications/livestream_connector.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import asyncio
2+
import logging
23
import tomllib
34
from datetime import date
45
from pathlib import Path
56

67
import aiofiles
78

9+
logger = logging.getLogger(__name__)
10+
811

912
class LivestreamConnector:
1013
def __init__(self, livestreams_file: Path) -> None:
@@ -40,17 +43,22 @@ async def fetch_livestreams(self) -> None:
4043
livestreams_raw = await self._open_livestreams_file()
4144
self.livestreams_by_room = await self._parse_livestreams(livestreams_raw)
4245

43-
async def get_livestream_url(self, room: str, date: date) -> None:
46+
async def get_livestream_url(self, room: str, day: date) -> str | None:
4447
"""
4548
Get the livestream URL for the given room and date.
4649
4750
:param room: The room name.
48-
:param date: The date of the livestream.
51+
:param day: The date of the livestream.
4952
5053
:return: The URL of the livestream.
5154
"""
5255
if not self.livestreams_by_room:
5356
await self.fetch_livestreams()
57+
5458
if room not in self.livestreams_by_room:
59+
logger.warning(f"Found no livestream URLs for room {room!r}")
60+
return None
61+
if day not in self.livestreams_by_room[room]:
62+
logger.warning(f"Found no livestream URLs for room {room!r} and day {day!r}")
5563
return None
56-
return self.livestreams_by_room[room][date]
64+
return self.livestreams_by_room[room][day]

0 commit comments

Comments
 (0)