Changed return type to a Message from the shared models library
This commit is contained in:
1 parent
6fe522abeb
commit
82a073ecb9
2 files changed
+43
-23
No files matched your search
@@ -1,23 +0,0 @@
|
||||
from typing import assert_never
|
||||
|
||||
from models import SourceType
|
||||
|
||||
def _bvb(event: str) -> list[str]:
|
||||
entries = event.split("|")
|
||||
event = entries[0]
|
||||
if entries[1].strip().lower() == "ucl":
|
||||
competition = f"{entries[1].strip()} - {entries[2].strip()}"
|
||||
match_day = entries[3].strip()
|
||||
else:
|
||||
competition = entries[1].strip()
|
||||
match_day = entries[2].strip()
|
||||
return [entries, competition, match_day]
|
||||
|
||||
def event_formatting(event: str, source: SourceType) -> list[str]:
|
||||
match source:
|
||||
case SourceType.BVB:
|
||||
return _bvb(event)
|
||||
case SourceType.GENERIC:
|
||||
return [event]
|
||||
case _:
|
||||
assert_never(source)
|
||||
@@ -0,0 +1,43 @@
|
||||
from typing import assert_never
|
||||
|
||||
from models import SourceType, CalendarEntry
|
||||
from shared_models import Message, Category
|
||||
from simple_logger_handler import setup_logger
|
||||
|
||||
logger = setup_logger(__name__)
|
||||
|
||||
def _bvb(entry: CalendarEntry) -> Message:
|
||||
parts = [p.strip() for p in entry.summary.split("|")]
|
||||
|
||||
try:
|
||||
match_name, competition, *rest = parts
|
||||
if competition.lower() == "ucl":
|
||||
stage, match_day = rest[0], rest[1]
|
||||
competition = f"{competition} - {stage}"
|
||||
else:
|
||||
match_day = rest[0]
|
||||
except (ValueError, IndexError):
|
||||
logger.warning("[BVB] Unexpected summary format, using generic: %s", entry.summary)
|
||||
return _generic(entry)
|
||||
|
||||
return Message(
|
||||
title=match_name,
|
||||
body=f"{competition} · {match_day} · {entry.date:%a %d %b, %H:%M}",
|
||||
category=Category.WATCHING,
|
||||
)
|
||||
|
||||
def _generic(entry: CalendarEntry) -> Message:
|
||||
return Message(
|
||||
title=entry.summary,
|
||||
body=f"{entry.date:%a %d %b, %H:%M}",
|
||||
category=Category.WATCHING
|
||||
)
|
||||
|
||||
def format_event(entry: CalendarEntry, source: SourceType) -> Message:
|
||||
match source:
|
||||
case SourceType.BVB:
|
||||
return _bvb(entry)
|
||||
case SourceType.GENERIC:
|
||||
return _generic(entry)
|
||||
case _:
|
||||
assert_never(source)
|
||||
Reference in new issue
Block a user