From 7a19f9acb711d08e7bde7604715cda27ee2e160d Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Fri, 1 Nov 2024 10:38:43 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9F=A2=20README.md:=20Updated=20command?= =?UTF-8?q?=20to=20retrieve=20schedule=20and=20added=20new=20commands=20fo?= =?UTF-8?q?r=20searching=20events=20by=20age=20group=20and=20retrieving=20?= =?UTF-8?q?match=20details?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🛠️ myice/myice.py: Implemented a function to parse the schedule JSON file based on given age groups, improved error handling, enhanced formatting when printing results, added a new command `myice search` --- README.md | 56 +++++++++++++++++++++++++------------------------- myice/myice.py | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 315c31a..df288fd 100644 --- a/README.md +++ b/README.md @@ -3,47 +3,47 @@ ## récupérer le schedule ```shell -./myice.py schedule -o schedule.json +myice schedule -o schedule.json ``` ## data +### listing + Pour récupérer les event des U13 Elite par exemple: ```shell -❯ jq -r '.[] | select(.agegroup == "U13 (Elite)") | [.date, .id_event, .event, .title] | join(" - ")' schedule.json -2024-11-01 - 561896 - - U13 (Elite) -Spécial -Shooting Box Groupe #3 -2024-11-01 - 561904 - - U13 (Elite) -Off-Ice -Patinoire des Vernets - Patinoire Extérieure -2024-11-01 - 561855 - - U13 (Elite) -On-Ice -Patinoire des Vernets - Patinoire Extérieure -2024-11-04 - 576653 - - U13 (Elite) -Off-Ice -Patinoire des Vernets - Patinoire Extérieure -2024-11-04 - 572066 - - U13 (Elite) -On-Ice -Patinoire des Vernets - Patinoire Extérieure -2024-11-05 - 576652 - - U13 (Elite) -Off-Ice -Patinoire des Vernets - Patinoire Extérieure -2024-11-05 - 572068 - - U13 (Elite) -On-Ice -Patinoire des Vernets - Patinoire Extérieure -2024-11-02 - 117015 - Jeu - U13 (Elite) -Saison -HC Ajoie +❯ myice search "U13 (Elite)" +[576653] 2024-11-04 practice 17:00-> 17:00 +practice: Off-Ice Patinoire des Vernets - Patinoire Extérieure + +[572066] 2024-11-04 practice 18:00-> 18:00 +practice: On-Ice Patinoire des Vernets - Patinoire Extérieure + +[576652] 2024-11-05 practice 18:00-> 18:00 +practice: Off-Ice Patinoire des Vernets - Patinoire Extérieure + +[572068] 2024-11-05 practice 19:15-> 19:15 +practice: On-Ice Patinoire des Vernets - Patinoire Extérieure + +[576655] 2024-11-08 practice 18:00-> 18:00 +practice: Off-Ice Patinoire des Vernets - Patinoire Extérieure + +[572073] 2024-11-08 practice 19:15-> 19:15 +practice: On-Ice Patinoire des Vernets - Patinoire Extérieure + +[117015] 2024-11-02 game 12:15-> 12:15 +game: Saison HC Ajoie ``` +Et on récupère la convoc du match: + ### match alors pour avoir la convocation du match contre Ajoie, l'id c'est 117015: ```shell -❯ ./get_schedule.py game 117015 +❯ myice game 117015 Opening file game_117015.pdf ``` @@ -53,7 +53,7 @@ Opening file game_117015.pdf et pour la convoc d'un entraînement: ```shell -❯ ./myice.py practice 561855 +❯ myice practice 561855 Opening file practice_561855.pdf ``` diff --git a/myice/myice.py b/myice/myice.py index bba2e9d..fc74051 100755 --- a/myice/myice.py +++ b/myice/myice.py @@ -9,6 +9,7 @@ import json import os import re import sys +from enum import Enum from pathlib import Path from typing import Annotated import requests @@ -21,6 +22,15 @@ session: requests.Session userid: int +class AgeGroup(str, Enum): + u13e = "U13 (Elite)" + u13t = "U13 (Top)" + u13a = "U13 (A)" + u13p = "U13 (Prép)" + u15t = "U15 (Top)" + u15a = "U15 (A)" + + def load_cookies(file: str = "cookies.txt") -> requests.cookies.RequestsCookieJar: cookie_jar_file = Path(file) cj_dict = {} @@ -233,5 +243,35 @@ def get_practice_pdf( open(output_filename) +@app.command("search") +def parse_schedule( + age_group: Annotated[AgeGroup, typer.Argument(...)], + schedule_file: Annotated[ + Path, typer.Option(help="schedule json file to parse") + ] = Path("schedule.json"), +): + """ + Parse schedule.json to look for specific games or practices + """ + 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") + title = " ".join(raw_title.split("\n")) + start = datetime.datetime.fromisoformat(event["start"]) + start_fmt = start.strftime("%H:%M") + end = datetime.datetime.fromisoformat(event["end"]) + end_fmt = end.strftime("%H:%M") + if "event" in event and event["event"] == "Jeu": + event_type = "game" + else: + event_type = "practice" + print( + f"[{event['id_event']}] {event['date']} {event_type} {start_fmt}-> {end_fmt}" + ) + print(f"{event_type}: {title}\n") + + if __name__ == "__main__": app()