feat: add club selection support and improve mobile API integration
This commit is contained in:
@@ -163,7 +163,9 @@ def save_cookies(file: str = "cookies.txt"):
|
||||
f.write(json.dumps(requests.utils.dict_from_cookiejar(session.cookies)))
|
||||
|
||||
|
||||
def get_login(local_file: str = "myice.ini") -> tuple[str, str, int | None, str | None]:
|
||||
def get_login(
|
||||
local_file: str = "myice.ini",
|
||||
) -> tuple[str, str, int | None, str | None, int | None]:
|
||||
config = configparser.ConfigParser()
|
||||
config.read(
|
||||
[
|
||||
@@ -179,6 +181,7 @@ def get_login(local_file: str = "myice.ini") -> tuple[str, str, int | None, str
|
||||
password = default_config.get("password")
|
||||
userid = default_config.getint("userid")
|
||||
token = default_config.get("token")
|
||||
club_id = default_config.getint("club_id")
|
||||
if not username or not password:
|
||||
print(
|
||||
"Error: please configure username/password in ini file", file=sys.stderr
|
||||
@@ -187,13 +190,22 @@ def get_login(local_file: str = "myice.ini") -> tuple[str, str, int | None, str
|
||||
else:
|
||||
print("Error: please configure username/password in ini file", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
return username, password, userid, token
|
||||
return username, password, userid, token, club_id
|
||||
|
||||
|
||||
def select_club(club_id: int = 172):
|
||||
"""Select a club by ID after login."""
|
||||
global session
|
||||
r = session.get(
|
||||
f"https://app.myice.hockey/?cl={club_id}", headers={"User-Agent": user_agent}
|
||||
)
|
||||
r.raise_for_status()
|
||||
|
||||
|
||||
def do_login():
|
||||
global session
|
||||
global userid
|
||||
username, password, userid, token = get_login()
|
||||
username, password, userid, token, club_id = get_login()
|
||||
r = session.get("https://app.myice.hockey/", headers={"User-Agent": user_agent})
|
||||
r.raise_for_status()
|
||||
form_data = {
|
||||
@@ -213,8 +225,7 @@ def do_login():
|
||||
)
|
||||
r.raise_for_status()
|
||||
# select the club we want
|
||||
session.get("https://app.myice.hockey/?cl=172", headers={"User-Agent": user_agent})
|
||||
r.raise_for_status()
|
||||
select_club(club_id)
|
||||
|
||||
|
||||
def get_userid():
|
||||
@@ -246,7 +257,7 @@ def wrapper_session(func):
|
||||
print("login...", file=sys.stderr)
|
||||
do_login()
|
||||
save_cookies()
|
||||
_, _, userid, _ = get_login()
|
||||
_, _, userid, _, _ = get_login()
|
||||
if not userid:
|
||||
print("get userid...", file=sys.stderr)
|
||||
userid = get_userid()
|
||||
@@ -515,7 +526,11 @@ mobile_headers = {
|
||||
def mobile_login():
|
||||
import base64
|
||||
|
||||
username, password, userid, token = get_login()
|
||||
username, password, _, token, club_id = get_login()
|
||||
if token and club_id:
|
||||
return {"id": 0, "token": token, "id_club": club_id}
|
||||
|
||||
print("Requesting token", file=sys.stderr)
|
||||
with requests.post(
|
||||
"https://app.myice.hockey/api/mobilerest/login",
|
||||
headers=mobile_headers,
|
||||
@@ -524,9 +539,10 @@ def mobile_login():
|
||||
) as r:
|
||||
r.raise_for_status()
|
||||
return {
|
||||
"id": r.json()["userid"],
|
||||
"id": 0,
|
||||
"token": r.json()["userinfo"]["token"],
|
||||
"id_club": r.json()["userinfo"]["id_club"],
|
||||
"id_club": club_id
|
||||
or r.json()["userinfo"]["id_club"], # Use configured club_id if available
|
||||
}
|
||||
|
||||
|
||||
@@ -541,54 +557,35 @@ def refresh_data():
|
||||
with requests.post(
|
||||
"https://app.myice.hockey/api/mobilerest/refreshdata",
|
||||
headers=mobile_headers,
|
||||
data=f"token={userdata['token']}&id_club=186&language=FR",
|
||||
# verify=False,
|
||||
data=f"token={userdata['token']}&id_club={userdata['id_club']}&language=FR",
|
||||
verify=False,
|
||||
) as r:
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
|
||||
@app.command("mobile")
|
||||
def mobile(
|
||||
token: Annotated[str, typer.Option(envvar="MYICE_TOKEN")] = "",
|
||||
id_club: Annotated[int, typer.Option(envvar="MYICE_CLUB")] = 0,
|
||||
):
|
||||
@app.command("mobile-login")
|
||||
def do_mobile_login():
|
||||
global userdata
|
||||
if not token:
|
||||
userdata = mobile_login()
|
||||
else:
|
||||
userdata = {
|
||||
"id": 0,
|
||||
"id_club": id_club,
|
||||
"token": token,
|
||||
}
|
||||
print(json.dumps(refresh_data(), indent=2))
|
||||
userdata = mobile_login()
|
||||
print(json.dumps(userdata, indent=2))
|
||||
|
||||
|
||||
@app.command("mobile")
|
||||
def mobile():
|
||||
global userdata
|
||||
userdata = mobile_login()
|
||||
games = [x for x in refresh_data().get("club_games")]
|
||||
print(json.dumps(games, indent=2))
|
||||
|
||||
|
||||
@app.command("mobile-game")
|
||||
def mobile_game(
|
||||
game_id: Annotated[int, typer.Argument(help="game id")],
|
||||
token: Annotated[str, typer.Option(envvar="MYICE_TOKEN")] = "",
|
||||
id_club: Annotated[int, typer.Option(envvar="MYICE_CLUB")] = 0,
|
||||
raw: Annotated[bool, typer.Option(help="display raw output")] = False,
|
||||
):
|
||||
global userdata
|
||||
username, password, userid, existing_token = get_login()
|
||||
if token:
|
||||
userdata = {
|
||||
"id": 0,
|
||||
"id_club": 186,
|
||||
"token": token,
|
||||
}
|
||||
else:
|
||||
if existing_token:
|
||||
userdata = {
|
||||
"id": userid,
|
||||
"id_club": 186,
|
||||
"token": existing_token,
|
||||
}
|
||||
else:
|
||||
userdata = mobile_login()
|
||||
userdata = mobile_login()
|
||||
|
||||
# data = refresh_data()
|
||||
with requests.post(
|
||||
@@ -604,7 +601,7 @@ def mobile_game(
|
||||
"language=FR",
|
||||
]
|
||||
),
|
||||
# verify=False,
|
||||
verify=False,
|
||||
) as r:
|
||||
data = r.json()["eventData"]
|
||||
players = data["convocation"]["available"]
|
||||
|
||||
Reference in New Issue
Block a user