🟢 README.md: Updated command to retrieve schedule and added new commands for searching events by age group and retrieving match details
🛠️ 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`
This commit is contained in:
56
README.md
56
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
|
||||
|
||||
```
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user