4 Commits

Author SHA1 Message Date
herel 6ad0587246 🟢 LICENSE.txt (New MIT license added)
🛠️ pyproject.toml -> Updated poetry dependencies, authors email changed, added license info
2024-11-01 10:41:39 +01:00
herel 7a19f9acb7 🟢 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`
2024-11-01 10:38:43 +01:00
herel 6c502f94f1 chore: add from Python.gitignore 2024-11-01 10:07:04 +01:00
herel e102cfa9c8 initial import 2024-11-01 09:59:45 +01:00
3 changed files with 10 additions and 32 deletions
+7 -29
View File
@@ -31,11 +31,6 @@ 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 = {}
@@ -216,7 +211,7 @@ def schedule(
print(schedule) print(schedule)
def os_open(file: str) -> None: def open(file: str) -> None:
if os.uname().sysname == "Linux": if os.uname().sysname == "Linux":
os.system(f"xdg-open {file}") os.system(f"xdg-open {file}")
else: else:
@@ -233,7 +228,7 @@ def get_game_pdf(
""" """
output_filename = f"game_{game_id}.pdf" output_filename = f"game_{game_id}.pdf"
game_pdf(game_id, Path(output_filename)) game_pdf(game_id, Path(output_filename))
os_open(output_filename) open(output_filename)
@app.command("practice") @app.command("practice")
@@ -245,16 +240,12 @@ def get_practice_pdf(
""" """
output_filename = f"practice_{game_id}.pdf" output_filename = f"practice_{game_id}.pdf"
practice_pdf(game_id, Path(output_filename)) practice_pdf(game_id, Path(output_filename))
os_open(output_filename) open(output_filename)
@app.command("search") @app.command("search")
def parse_schedule( def parse_schedule(
age_group: Annotated[AgeGroup | None, typer.Option(...)] = None, age_group: Annotated[AgeGroup, typer.Argument(...)],
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"),
@@ -264,22 +255,9 @@ 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)
# age_group filter for event in [x for x in data if x["agegroup"] == age_group]:
if age_group: # print(json.dumps(event, indent=2))
events = [x for x in data if x["agegroup"] == age_group] raw_title = event["title"].removeprefix(age_group + "\n")
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")
Generated
+1 -1
View File
@@ -1025,4 +1025,4 @@ files = [
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "^3.12" python-versions = "^3.12"
content-hash = "32eb77391a5bfd29bed30f4a384ccd08ca307923ac47c48eaad6bfee18798081" content-hash = "e11a9960c50f8b210bd0942533a30915eb56bed47cf5f67ac33f405cb1ef5859"
+2 -2
View File
@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "myice" name = "myice"
version = "v0.1.3" version = "0.1.0"
description = "myice parsing" description = "myice parsing"
authors = ["Rene Luria <rene@luria.ch>"] authors = ["Rene Luria <rene@luria.ch>"]
license = "MIT" license = "MIT"
@@ -9,7 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.12" python = "^3.12"
requests = "^2.32.3" requests = "^2.32.3"
typer = "^0.12.5" typer = {extras = ["all"], version = "^0.12.5"}
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]