🛠️ myice/myice.py -> added EventType enum and updated search command to support optional event type filtering
- Added `EventType` enum with two values: 'game' and 'practice'. - Updated `parse_schedule` function to accept an optional `event_type_filter` argument which filters displayed events based on their type. - Changed `age_group` parameter in `parse_schedule` to allow `None`.
This commit is contained in:
@@ -31,6 +31,11 @@ class AgeGroup(str, Enum):
|
||||
u15a = "U15 (A)"
|
||||
|
||||
|
||||
class EventType(str, Enum):
|
||||
game = "game"
|
||||
practice = "practice"
|
||||
|
||||
|
||||
def load_cookies(file: str = "cookies.txt") -> requests.cookies.RequestsCookieJar:
|
||||
cookie_jar_file = Path(file)
|
||||
cj_dict = {}
|
||||
@@ -47,12 +52,14 @@ def save_cookies():
|
||||
|
||||
def get_login(local_file: str = "myice.ini") -> tuple[str, str, int]:
|
||||
config = configparser.ConfigParser()
|
||||
config.read(
|
||||
[
|
||||
Path("~/.config/myice.ini").expanduser(),
|
||||
"myice.ini",
|
||||
local_file,
|
||||
]
|
||||
print(
|
||||
config.read(
|
||||
[
|
||||
Path("~/.config/myice.ini").expanduser(),
|
||||
"myice.ini",
|
||||
local_file,
|
||||
]
|
||||
)
|
||||
)
|
||||
if "default" in config.sections():
|
||||
default_config = config["default"]
|
||||
@@ -245,7 +252,11 @@ def get_practice_pdf(
|
||||
|
||||
@app.command("search")
|
||||
def parse_schedule(
|
||||
age_group: Annotated[AgeGroup, typer.Argument(...)],
|
||||
age_group: Annotated[AgeGroup | None, typer.Option(...)] = None,
|
||||
event_type_filter: Annotated[
|
||||
EventType | None,
|
||||
typer.Option("--type", help="Only display events of this type"),
|
||||
] = None,
|
||||
schedule_file: Annotated[
|
||||
Path, typer.Option(help="schedule json file to parse")
|
||||
] = Path("schedule.json"),
|
||||
@@ -255,9 +266,22 @@ def parse_schedule(
|
||||
"""
|
||||
with schedule_file.open("r") as f:
|
||||
data = json.load(f)
|
||||
for event in [x for x in data if x["agegroup"] == age_group]:
|
||||
# print(json.dumps(event, indent=2))
|
||||
raw_title = event["title"].removeprefix(age_group + "\n")
|
||||
# age_group filter
|
||||
if age_group:
|
||||
events = [x for x in data if x["agegroup"] == age_group]
|
||||
else:
|
||||
events = [x for x in data if x["agegroup"] in AgeGroup]
|
||||
# event_type filter
|
||||
if event_type_filter:
|
||||
if event_type_filter.value == EventType.game:
|
||||
events = [x for x in events if "event" in x and x["event"] == "Jeu"]
|
||||
else:
|
||||
events = [x for x in events if "event" not in x or x["event"] == "Jeu"]
|
||||
for event in events:
|
||||
if age_group:
|
||||
raw_title = event["title"].removeprefix(age_group + "\n")
|
||||
else:
|
||||
raw_title = event["title"]
|
||||
title = " ".join(raw_title.split("\n"))
|
||||
start = datetime.datetime.fromisoformat(event["start"])
|
||||
start_fmt = start.strftime("%H:%M")
|
||||
|
||||
Reference in New Issue
Block a user