This commit is contained in:
2024-08-09 22:44:26 +02:00
parent 674b44089f
commit 612d07a6c4
2 changed files with 15 additions and 10 deletions

View File

@@ -12,20 +12,24 @@ class GameItem(BaseModel):
date: str | None date: str | None
def __str__(self) -> str: def __str__(self) -> str:
# set timezone to Moscow if self.date is not None:
_date = self.date or datetime.now().strftime("%d.%m.%Y") return f"* {self.name} ({self.customer}) | {self.date}"
return f"* {self.name} ({self.customer}) | {_date}" else:
return f"* {self.name} ({self.customer})"
@classmethod @classmethod
def parse(cls, line: str) -> Self: 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: regex_result_without_date = re.search(r"^\* (.+) \((.+)\)$", line)
raise ValueError(f"Invalid game item: {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() raise ValueError(f"Invalid line: {line}")
return cls(name=name, customer=customer, date=date)
class Category(BaseModel): class Category(BaseModel):

View File

@@ -62,8 +62,9 @@ class TwitchService:
@classmethod @classmethod
async def start(cls): async def start(cls):
twith = await cls.authorize() print("Starting Twitch service...")
twith = await cls.authorize()
await cls(twith).run() await cls(twith).run()