Compare commits
13 Commits
v0.1.0
..
6f3c7bf8d2
| Author | SHA1 | Date | |
|---|---|---|---|
|
6f3c7bf8d2
|
|||
|
2c67596d38
|
|||
|
a39899ebb1
|
|||
|
320ec291e6
|
|||
|
85f84b540a
|
|||
|
7939414995
|
|||
|
b2baa07371
|
|||
|
56e7ba92e8
|
|||
|
a3e1d9ccbf
|
|||
|
3b2351efc6
|
|||
|
e313b824d7
|
|||
|
11bbfdfc10
|
|||
|
1644523d40
|
@@ -1,5 +1,24 @@
|
||||
# myice
|
||||
|
||||
## intro
|
||||
|
||||
Avec tout ça on va aller chercher sur MyIce les planning des gamins et générer
|
||||
les pdf qu'on veut
|
||||
|
||||
## install
|
||||
|
||||
with [uv](https://docs.astral.sh/uv/getting-started/installation/):
|
||||
|
||||
```shell
|
||||
uv tool install --extra-index-url https://gitea.parano.ch/api/packages/herel/pypi/simple/ myice
|
||||
```
|
||||
|
||||
with [pipx](https://pipx.pypa.io/stable/installation/):
|
||||
|
||||
```shell
|
||||
pipx install --extra-index-url https://gitea.parano.ch/api/packages/herel/pypi/simple/ myice
|
||||
```
|
||||
|
||||
## récupérer le schedule
|
||||
|
||||
```shell
|
||||
|
||||
+67
-13
@@ -12,6 +12,8 @@ import sys
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Annotated
|
||||
from typing import List, Tuple
|
||||
from rl_ai_tools import utils # type: ignore
|
||||
import requests
|
||||
import typer
|
||||
|
||||
@@ -31,6 +33,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 = {}
|
||||
@@ -40,8 +47,9 @@ def load_cookies(file: str = "cookies.txt") -> requests.cookies.RequestsCookieJa
|
||||
return requests.cookies.cookiejar_from_dict(cj_dict)
|
||||
|
||||
|
||||
def save_cookies():
|
||||
with open("cookies.txt", "w") as f:
|
||||
def save_cookies(file: str = "cookies.txt"):
|
||||
cookie_jar_file = Path(file)
|
||||
with cookie_jar_file.open("w") as f:
|
||||
f.write(json.dumps(requests.utils.dict_from_cookiejar(session.cookies)))
|
||||
|
||||
|
||||
@@ -61,10 +69,12 @@ def get_login(local_file: str = "myice.ini") -> tuple[str, str, int]:
|
||||
password = default_config.get("password")
|
||||
userid = default_config.getint("userid")
|
||||
if not username or not password:
|
||||
print("Error: please configure username/password in ini file")
|
||||
print(
|
||||
"Error: please configure username/password in ini file", file=sys.stderr
|
||||
)
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Error: please configure username/password in ini file")
|
||||
print("Error: please configure username/password in ini file", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return username, password, userid
|
||||
|
||||
@@ -118,12 +128,12 @@ def wrapper_session(func):
|
||||
session.cookies = load_cookies()
|
||||
session.cookies.clear_expired_cookies()
|
||||
if not session.cookies.get("mih_v3_cookname"):
|
||||
print("login...")
|
||||
print("login...", file=sys.stderr)
|
||||
do_login()
|
||||
save_cookies()
|
||||
_, _, userid = get_login()
|
||||
if not userid:
|
||||
print("get userid...")
|
||||
print("get userid...", file=sys.stderr)
|
||||
userid = get_userid()
|
||||
return func(*args, **kwargs)
|
||||
|
||||
@@ -207,11 +217,10 @@ def schedule(
|
||||
with outfile.open("w") as f:
|
||||
f.write(schedule)
|
||||
else:
|
||||
print("Schedule:", file=sys.stderr)
|
||||
print(schedule)
|
||||
|
||||
|
||||
def open(file: str) -> None:
|
||||
def os_open(file: str) -> None:
|
||||
if os.uname().sysname == "Linux":
|
||||
os.system(f"xdg-open {file}")
|
||||
else:
|
||||
@@ -228,7 +237,7 @@ def get_game_pdf(
|
||||
"""
|
||||
output_filename = f"game_{game_id}.pdf"
|
||||
game_pdf(game_id, Path(output_filename))
|
||||
open(output_filename)
|
||||
os_open(output_filename)
|
||||
|
||||
|
||||
@app.command("practice")
|
||||
@@ -240,12 +249,16 @@ def get_practice_pdf(
|
||||
"""
|
||||
output_filename = f"practice_{game_id}.pdf"
|
||||
practice_pdf(game_id, Path(output_filename))
|
||||
open(output_filename)
|
||||
os_open(output_filename)
|
||||
|
||||
|
||||
@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 +268,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))
|
||||
# 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")
|
||||
@@ -273,5 +299,33 @@ def parse_schedule(
|
||||
print(f"{event_type}: {title}\n")
|
||||
|
||||
|
||||
@app.command("ai")
|
||||
def check_with_ai(
|
||||
schedule_file: Annotated[
|
||||
Path, typer.Option(help="schedule json file to parse")
|
||||
] = Path("schedule.json"),
|
||||
):
|
||||
"""
|
||||
Search through the schedule with natural language using Infomaniak LLM API
|
||||
"""
|
||||
if not utils.init():
|
||||
sys.exit(1)
|
||||
with schedule_file.open("r") as f:
|
||||
schedule_data = json.load(f)
|
||||
system = (
|
||||
"Tu es une IA connaissant bien les données suivantes, qui décrivent les match et entraînements d'équipes de hockey sur glace:\n"
|
||||
+ json.dumps(schedule_data)
|
||||
)
|
||||
history: List[Tuple[str, str]] = []
|
||||
while True:
|
||||
try:
|
||||
question = input("> ")
|
||||
except EOFError:
|
||||
break
|
||||
answer = utils.llm_inference(question, history, system=system)
|
||||
print(">", answer)
|
||||
history.append((question, answer))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
|
||||
Generated
+21
-1
@@ -890,6 +890,26 @@ pygments = ">=2.13.0,<3.0.0"
|
||||
[package.extras]
|
||||
jupyter = ["ipywidgets (>=7.5.1,<9)"]
|
||||
|
||||
[[package]]
|
||||
name = "rl-ai-tools"
|
||||
version = "1.9.0"
|
||||
description = "Tools using AI"
|
||||
optional = false
|
||||
python-versions = ">=3.11,<4.0"
|
||||
files = [
|
||||
{file = "rl_ai_tools-1.9.0-py3-none-any.whl", hash = "sha256:c986a17e39afe6bd5bc21eb8d259e465dcc52e60a73b81db3931b45599e94fc1"},
|
||||
{file = "rl_ai_tools-1.9.0.tar.gz", hash = "sha256:80c43d434a330544e5d201f3a99460996cc31276fb360cb45a0962f743a342bb"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
requests = ">=2.32.3,<3.0.0"
|
||||
typer = ">=0.12.5,<0.13.0"
|
||||
|
||||
[package.source]
|
||||
type = "legacy"
|
||||
url = "https://pypi.purple.infomaniak.ch"
|
||||
reference = "infomaniak"
|
||||
|
||||
[[package]]
|
||||
name = "shellingham"
|
||||
version = "1.5.4"
|
||||
@@ -1025,4 +1045,4 @@ files = [
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.12"
|
||||
content-hash = "e11a9960c50f8b210bd0942533a30915eb56bed47cf5f67ac33f405cb1ef5859"
|
||||
content-hash = "c8b74100d5c4f5889db217b5fb249f55248d1955787fd76dbda5ded8b73875b3"
|
||||
|
||||
+9
-2
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "myice"
|
||||
version = "0.1.0"
|
||||
version = "v0.2.0"
|
||||
description = "myice parsing"
|
||||
authors = ["Rene Luria <rene@luria.ch>"]
|
||||
license = "MIT"
|
||||
@@ -9,12 +9,19 @@ readme = "README.md"
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.12"
|
||||
requests = "^2.32.3"
|
||||
typer = {extras = ["all"], version = "^0.12.5"}
|
||||
typer = "^0.12.5"
|
||||
rl-ai-tools = {version = "^1.9.0", source = "infomaniak"}
|
||||
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
ipykernel = "^6.29.5"
|
||||
|
||||
|
||||
[[tool.poetry.source]]
|
||||
name = "infomaniak"
|
||||
url = "https://pypi.purple.infomaniak.ch"
|
||||
priority = "supplemental"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
Reference in New Issue
Block a user