From 612d07a6c45f29e1af511b378e17d7d8dc1e4b91 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Fri, 9 Aug 2024 22:44:26 +0200 Subject: [PATCH] Fix --- src/services/games_list.py | 22 +++++++++++++--------- src/services/twitch.py | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/services/games_list.py b/src/services/games_list.py index dc228cb..e5e7de0 100644 --- a/src/services/games_list.py +++ b/src/services/games_list.py @@ -12,20 +12,24 @@ class GameItem(BaseModel): date: str | None def __str__(self) -> str: - # set timezone to Moscow - _date = self.date or datetime.now().strftime("%d.%m.%Y") - return f"* {self.name} ({self.customer}) | {_date}" + if self.date is not None: + return f"* {self.name} ({self.customer}) | {self.date}" + else: + return f"* {self.name} ({self.customer})" @classmethod def parse(cls, line: str) -> Self: - regex_result = re.search(r"^\* (.+) \((.+)\) \| (.+)$", line) + regex_result_with_date = re.search(r"^\* (.+) \((.+)\) \| (.+)$", line) + if regex_result_with_date is not None: + name, customer, date = regex_result_with_date.groups() + return cls(name=name, customer=customer, date=date) - if regex_result is None: - raise ValueError(f"Invalid game item: {line}") + regex_result_without_date = re.search(r"^\* (.+) \((.+)\)$", line) + if regex_result_without_date is not None: + name, customer = regex_result_without_date.groups() + return cls(name=name, customer=customer, date=None) - name, customer, date = regex_result.groups() - - return cls(name=name, customer=customer, date=date) + raise ValueError(f"Invalid line: {line}") class Category(BaseModel): diff --git a/src/services/twitch.py b/src/services/twitch.py index 30c4278..b5e69f2 100644 --- a/src/services/twitch.py +++ b/src/services/twitch.py @@ -62,8 +62,9 @@ class TwitchService: @classmethod async def start(cls): - twith = await cls.authorize() + print("Starting Twitch service...") + twith = await cls.authorize() await cls(twith).run()