🛠️ 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:
+34
-10
@@ -31,6 +31,11 @@ class AgeGroup(str, Enum):
|
|||||||
u15a = "U15 (A)"
|
u15a = "U15 (A)"
|
||||||
|
|
||||||
|
|
||||||
|
class EventType(str, Enum):
|
||||||
|
game = "game"
|
||||||
|
practice = "practice"
|
||||||
|
|
||||||
|
|
||||||
def load_cookies(file: str = "cookies.txt") -> requests.cookies.RequestsCookieJar:
|
def load_cookies(file: str = "cookies.txt") -> requests.cookies.RequestsCookieJar:
|
||||||
cookie_jar_file = Path(file)
|
cookie_jar_file = Path(file)
|
||||||
cj_dict = {}
|
cj_dict = {}
|
||||||
@@ -47,12 +52,14 @@ def save_cookies():
|
|||||||
|
|
||||||
def get_login(local_file: str = "myice.ini") -> tuple[str, str, int]:
|
def get_login(local_file: str = "myice.ini") -> tuple[str, str, int]:
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(
|
print(
|
||||||
[
|
config.read(
|
||||||
Path("~/.config/myice.ini").expanduser(),
|
[
|
||||||
"myice.ini",
|
Path("~/.config/myice.ini").expanduser(),
|
||||||
local_file,
|
"myice.ini",
|
||||||
]
|
local_file,
|
||||||
|
]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if "default" in config.sections():
|
if "default" in config.sections():
|
||||||
default_config = config["default"]
|
default_config = config["default"]
|
||||||
@@ -245,7 +252,11 @@ def get_practice_pdf(
|
|||||||
|
|
||||||
@app.command("search")
|
@app.command("search")
|
||||||
def parse_schedule(
|
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[
|
schedule_file: Annotated[
|
||||||
Path, typer.Option(help="schedule json file to parse")
|
Path, typer.Option(help="schedule json file to parse")
|
||||||
] = Path("schedule.json"),
|
] = Path("schedule.json"),
|
||||||
@@ -255,9 +266,22 @@ def parse_schedule(
|
|||||||
"""
|
"""
|
||||||
with schedule_file.open("r") as f:
|
with schedule_file.open("r") as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
for event in [x for x in data if x["agegroup"] == age_group]:
|
# age_group filter
|
||||||
# print(json.dumps(event, indent=2))
|
if age_group:
|
||||||
raw_title = event["title"].removeprefix(age_group + "\n")
|
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"))
|
title = " ".join(raw_title.split("\n"))
|
||||||
start = datetime.datetime.fromisoformat(event["start"])
|
start = datetime.datetime.fromisoformat(event["start"])
|
||||||
start_fmt = start.strftime("%H:%M")
|
start_fmt = start.strftime("%H:%M")
|
||||||
|
|||||||
Reference in New Issue
Block a user