Compare commits
11 Commits
v0.1.0
..
a39899ebb1
| Author | SHA1 | Date | |
|---|---|---|---|
|
a39899ebb1
|
|||
|
320ec291e6
|
|||
|
85f84b540a
|
|||
|
7939414995
|
|||
|
b2baa07371
|
|||
|
56e7ba92e8
|
|||
|
a3e1d9ccbf
|
|||
|
3b2351efc6
|
|||
|
e313b824d7
|
|||
|
11bbfdfc10
|
|||
|
1644523d40
|
@@ -1,5 +1,24 @@
|
|||||||
# myice
|
# 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
|
## récupérer le schedule
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
+37
-13
@@ -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 = {}
|
||||||
@@ -40,8 +45,9 @@ def load_cookies(file: str = "cookies.txt") -> requests.cookies.RequestsCookieJa
|
|||||||
return requests.cookies.cookiejar_from_dict(cj_dict)
|
return requests.cookies.cookiejar_from_dict(cj_dict)
|
||||||
|
|
||||||
|
|
||||||
def save_cookies():
|
def save_cookies(file: str = "cookies.txt"):
|
||||||
with open("cookies.txt", "w") as f:
|
cookie_jar_file = Path(file)
|
||||||
|
with cookie_jar_file.open("w") as f:
|
||||||
f.write(json.dumps(requests.utils.dict_from_cookiejar(session.cookies)))
|
f.write(json.dumps(requests.utils.dict_from_cookiejar(session.cookies)))
|
||||||
|
|
||||||
|
|
||||||
@@ -61,10 +67,12 @@ def get_login(local_file: str = "myice.ini") -> tuple[str, str, int]:
|
|||||||
password = default_config.get("password")
|
password = default_config.get("password")
|
||||||
userid = default_config.getint("userid")
|
userid = default_config.getint("userid")
|
||||||
if not username or not password:
|
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)
|
sys.exit(1)
|
||||||
else:
|
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)
|
sys.exit(1)
|
||||||
return username, password, userid
|
return username, password, userid
|
||||||
|
|
||||||
@@ -118,12 +126,12 @@ def wrapper_session(func):
|
|||||||
session.cookies = load_cookies()
|
session.cookies = load_cookies()
|
||||||
session.cookies.clear_expired_cookies()
|
session.cookies.clear_expired_cookies()
|
||||||
if not session.cookies.get("mih_v3_cookname"):
|
if not session.cookies.get("mih_v3_cookname"):
|
||||||
print("login...")
|
print("login...", file=sys.stderr)
|
||||||
do_login()
|
do_login()
|
||||||
save_cookies()
|
save_cookies()
|
||||||
_, _, userid = get_login()
|
_, _, userid = get_login()
|
||||||
if not userid:
|
if not userid:
|
||||||
print("get userid...")
|
print("get userid...", file=sys.stderr)
|
||||||
userid = get_userid()
|
userid = get_userid()
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
@@ -207,11 +215,10 @@ def schedule(
|
|||||||
with outfile.open("w") as f:
|
with outfile.open("w") as f:
|
||||||
f.write(schedule)
|
f.write(schedule)
|
||||||
else:
|
else:
|
||||||
print("Schedule:", file=sys.stderr)
|
|
||||||
print(schedule)
|
print(schedule)
|
||||||
|
|
||||||
|
|
||||||
def open(file: str) -> None:
|
def os_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:
|
||||||
@@ -228,7 +235,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))
|
||||||
open(output_filename)
|
os_open(output_filename)
|
||||||
|
|
||||||
|
|
||||||
@app.command("practice")
|
@app.command("practice")
|
||||||
@@ -240,12 +247,16 @@ 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))
|
||||||
open(output_filename)
|
os_open(output_filename)
|
||||||
|
|
||||||
|
|
||||||
@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:
|
||||||
|
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")
|
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
@@ -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 = "e11a9960c50f8b210bd0942533a30915eb56bed47cf5f67ac33f405cb1ef5859"
|
content-hash = "32eb77391a5bfd29bed30f4a384ccd08ca307923ac47c48eaad6bfee18798081"
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "myice"
|
name = "myice"
|
||||||
version = "0.1.0"
|
version = "v0.1.6"
|
||||||
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 = {extras = ["all"], version = "^0.12.5"}
|
typer = "^0.12.5"
|
||||||
|
|
||||||
|
|
||||||
[tool.poetry.group.dev.dependencies]
|
[tool.poetry.group.dev.dependencies]
|
||||||
|
|||||||
Reference in New Issue
Block a user