Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| aa90dbe1f1 | |||
| c2ab852f3f | |||
| 6b5949b726 | |||
| 66b93af6b1 | |||
| 6eb9598012 | |||
| e7b0fdec00 | |||
| 4c53d6ce08 | |||
| 3ce916f5c4 | |||
| ea696ed361 | |||
| 6b09a95a45 | |||
| b11f875756 | |||
| 5b5b593a3b | |||
| 03d33f2e03 | |||
| 2bd10409a1 | |||
| f1955238c5 | |||
| 8af989f372 | |||
| 28b34d8281 | |||
| 251e2b1452 | |||
| 4c5867c19f | |||
| 75074991af | |||
| 0ac1659db2 | |||
| b5c3164f96 | |||
| 91d8824e9c | |||
| 6b37e0fcc2 | |||
| 5bf970ed26 | |||
| 37005c5ff0 | |||
| 2bf6b62ba4 | |||
| 275f1d09ca | |||
| e8e6f09e0a | |||
| f9bc440c1b | |||
| 324397fe27 | |||
| c1ad2ac9e0 | |||
| 49f72ef22e | |||
| bce52d2462 | |||
| c93c9fadd9 | |||
| 0346346a23 | |||
| 6ad0587246 | |||
| 7a19f9acb7 | |||
| 6c502f94f1 | |||
| e102cfa9c8 |
@@ -1,9 +1,9 @@
|
||||
# myice
|
||||
|
||||
## intro
|
||||
## introduction
|
||||
|
||||
Avec tout ça on va aller chercher sur MyIce les planning des gamins et générer
|
||||
les pdf qu'on veut
|
||||
With this tool, you can fetch kids' schedules from MyIce and generate
|
||||
the PDFs you need.
|
||||
|
||||
## install
|
||||
|
||||
@@ -19,17 +19,102 @@ with [pipx](https://pipx.pypa.io/stable/installation/):
|
||||
pipx install --extra-index-url https://gitea.parano.ch/api/packages/herel/pypi/simple/ myice
|
||||
```
|
||||
|
||||
## récupérer le schedule
|
||||
## configuration
|
||||
|
||||
Create a `myice.ini` file with your credentials:
|
||||
|
||||
```ini
|
||||
[default]
|
||||
username = your_email@example.com
|
||||
password = your_password
|
||||
userid = 12345
|
||||
token = your_api_token
|
||||
club_id = 172
|
||||
```
|
||||
|
||||
You can also create multiple sections for different users:
|
||||
|
||||
```ini
|
||||
[default]
|
||||
username = user1@example.com
|
||||
password = password1
|
||||
userid = 12345
|
||||
token = token1
|
||||
club_id = 172
|
||||
|
||||
[second_kid]
|
||||
username = charlie@example.com
|
||||
password = password2
|
||||
userid = 67890
|
||||
token = token2
|
||||
club_id = 186
|
||||
```
|
||||
|
||||
Note: The `userid`, `token`, and `club_id` fields are optional. If you don't
|
||||
have them, the tool can fetch them automatically using the mobile-login
|
||||
command (see below).
|
||||
|
||||
To fetch the `token` and `club_id` using mobile-login:
|
||||
|
||||
```shell
|
||||
myice mobile-login
|
||||
```
|
||||
|
||||
This will output the necessary information that you can add to your `myice.ini` file.
|
||||
|
||||
## web interface
|
||||
|
||||
The tool includes a web interface that can be accessed by running the web API server:
|
||||
|
||||
```shell
|
||||
uv run fastapi run myice/webapi.py
|
||||
```
|
||||
|
||||
Then open your browser at `http://localhost:8000`. The web interface allows you to:
|
||||
|
||||
- Select between different configured accounts
|
||||
- View upcoming games and practices
|
||||
- See detailed information about events including player rosters
|
||||
|
||||
The web API provides the following endpoints:
|
||||
|
||||
- `/schedule` - Get the schedule for a specific account
|
||||
- `/game/{game_id}` - Get details for a specific game
|
||||
- `/accounts` - Get a list of available accounts
|
||||
- `/health` - Health check endpoint
|
||||
|
||||
All endpoints (except `/health`) require an Authorization header with a Bearer token.
|
||||
For development purposes, you can use `abc` as the token.
|
||||
|
||||
## mobile functions
|
||||
|
||||
The tool includes several mobile API functions that interact with MyIce's
|
||||
mobile API:
|
||||
|
||||
- `myice mobile-login` - Authenticate and get authentication tokens
|
||||
- `myice mobile` - Fetch game data using the mobile API
|
||||
- `myice mobile-game {game_id}` - Get detailed information about a specific game
|
||||
|
||||
These functions can be useful for debugging or when the regular web
|
||||
interface is not available.
|
||||
|
||||
## fetch schedule
|
||||
|
||||
```shell
|
||||
myice schedule -o schedule.json
|
||||
```
|
||||
|
||||
To use a specific configuration section:
|
||||
|
||||
```shell
|
||||
myice schedule -o schedule.json --config-section isaac
|
||||
```
|
||||
|
||||
## data
|
||||
|
||||
### listing
|
||||
|
||||
Pour récupérer les event des U13 Elite par example:
|
||||
To fetch events for U13 Elite for example:
|
||||
|
||||
```shell
|
||||
❯ myice search "U13 (Elite)"
|
||||
@@ -55,11 +140,11 @@ practice: On-Ice Patinoire des Vernets - Patinoire Extérieure
|
||||
game: Saison HC Ajoie
|
||||
```
|
||||
|
||||
Et on récupère la convoc du match:
|
||||
And we retrieve the match roster:
|
||||
|
||||
### match
|
||||
|
||||
alors pour avoir la convocation du match contre Ajoie, l'id c'est 117015:
|
||||
To get the roster for the match against Ajoie, the ID is 117015:
|
||||
|
||||
```shell
|
||||
❯ myice game 117015
|
||||
@@ -67,9 +152,15 @@ Opening file game_117015.pdf
|
||||
|
||||
```
|
||||
|
||||
### entraînement
|
||||
To use a specific configuration section:
|
||||
|
||||
et pour la convoc d'un entraînement:
|
||||
```shell
|
||||
❯ myice game 117015 --config-section isaac
|
||||
```
|
||||
|
||||
### practice
|
||||
|
||||
And for a practice roster:
|
||||
|
||||
```shell
|
||||
❯ myice practice 561855
|
||||
@@ -77,6 +168,12 @@ Opening file practice_561855.pdf
|
||||
|
||||
```
|
||||
|
||||
To use a specific configuration section:
|
||||
|
||||
```shell
|
||||
❯ myice practice 561855 --config-section isaac
|
||||
```
|
||||
|
||||
### AI
|
||||
|
||||
```text
|
||||
@@ -86,3 +183,9 @@ Opening file practice_561855.pdf
|
||||
> et les u13 a ?
|
||||
< Le prochain match de l'équipe U13 A se déroulera le samedi 9 novembre 2024 contre HC Vallorbe à P. du Frézillon, 1337 Vallorbe VD. Le match débutera à 13h00 et se terminera à 15h00. Le prochain match à domicile de l'équipe U13 A se déroulera le dimanche 10 novembre 2024 contre CP Meyrin à Les Vernets, Glace extérieure, 1227 Les Acacias GE. Le match débutera à 13h00 et se terminera à 15h00.
|
||||
```
|
||||
|
||||
To use a specific configuration section:
|
||||
|
||||
```shell
|
||||
❯ myice ai --config-section isaac
|
||||
```
|
||||
|
||||
+53
-5
@@ -16,6 +16,12 @@
|
||||
<div id="apikeyContainer" class="mb-3"></div>
|
||||
|
||||
<div id="eventFilters" style="display: none;">
|
||||
<div class="mb-3">
|
||||
<label for="account" class="form-label">Sélectionner un compte</label>
|
||||
<select id="account" class="form-select">
|
||||
<option value="default">Compte par défaut</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="agegroup" class="form-label">Filtrer par groupe d'âge</label>
|
||||
<select id="agegroup" class="form-select">
|
||||
@@ -46,6 +52,7 @@
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const apikeyContainer = document.getElementById("apikeyContainer");
|
||||
const eventFilters = document.getElementById("eventFilters");
|
||||
const accountSelect = document.getElementById("account");
|
||||
const agegroupSelect = document.getElementById("agegroup");
|
||||
const eventList = document.getElementById("eventList");
|
||||
const fetchButton = document.getElementById("fetchEvents");
|
||||
@@ -54,16 +61,20 @@
|
||||
|
||||
let storedApiKey = localStorage.getItem("apikey");
|
||||
let lastFetchedEvents = [];
|
||||
let storedAccount = localStorage.getItem("account") || "default";
|
||||
|
||||
function renderApiKeyInput() {
|
||||
if (storedApiKey) {
|
||||
apikeyContainer.innerHTML = `<button id="disconnect" class="btn btn-danger">Déconnecter</button>`;
|
||||
document.getElementById("disconnect").addEventListener("click", () => {
|
||||
localStorage.removeItem("apikey");
|
||||
localStorage.removeItem("account");
|
||||
location.reload();
|
||||
});
|
||||
eventFilters.style.display = "block";
|
||||
fetchEvents(storedApiKey);
|
||||
// Load available accounts from server or use predefined ones
|
||||
updateAccountOptions();
|
||||
fetchEvents(storedApiKey, storedAccount);
|
||||
} else {
|
||||
apikeyContainer.innerHTML = `
|
||||
<label for="apikey" class="form-label">API Key</label>
|
||||
@@ -90,22 +101,58 @@
|
||||
}
|
||||
}
|
||||
|
||||
function updateAccountOptions() {
|
||||
// Fetch available accounts from the server
|
||||
fetch(`${apiBaseUrl}/accounts`, {
|
||||
headers: { "Authorization": `Bearer ${storedApiKey}` }
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(accounts => {
|
||||
accountSelect.innerHTML = '';
|
||||
accounts.forEach(account => {
|
||||
const option = document.createElement("option");
|
||||
option.value = account.name;
|
||||
option.textContent = account.label;
|
||||
if (account.name === storedAccount) {
|
||||
option.selected = true;
|
||||
}
|
||||
accountSelect.appendChild(option);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Erreur lors du chargement des comptes:", error);
|
||||
// Fallback to default options
|
||||
accountSelect.innerHTML = `
|
||||
<option value="default" ${storedAccount === "default" ? "selected" : ""}>Compte par défaut</option>
|
||||
`;
|
||||
});
|
||||
}
|
||||
|
||||
renderApiKeyInput();
|
||||
|
||||
accountSelect.addEventListener("change", () => {
|
||||
const selectedAccount = accountSelect.value;
|
||||
localStorage.setItem("account", selectedAccount);
|
||||
if (storedApiKey) {
|
||||
fetchEvents(storedApiKey, selectedAccount);
|
||||
}
|
||||
});
|
||||
|
||||
fetchButton.addEventListener("click", () => {
|
||||
if (!storedApiKey) {
|
||||
alert("Veuillez entrer une clé API");
|
||||
return;
|
||||
}
|
||||
fetchEvents(storedApiKey);
|
||||
const selectedAccount = accountSelect.value;
|
||||
fetchEvents(storedApiKey, selectedAccount);
|
||||
});
|
||||
|
||||
agegroupSelect.addEventListener("change", () => {
|
||||
displayEvents(lastFetchedEvents);
|
||||
});
|
||||
|
||||
function fetchEvents(apiKey) {
|
||||
fetch(`${apiBaseUrl}/schedule`, {
|
||||
function fetchEvents(apiKey, account) {
|
||||
fetch(`${apiBaseUrl}/schedule?account=${account}`, {
|
||||
headers: { "Authorization": `Bearer ${apiKey}` }
|
||||
})
|
||||
.then(response => response.json())
|
||||
@@ -156,7 +203,8 @@
|
||||
}
|
||||
|
||||
function fetchEventDetails(eventId) {
|
||||
fetch(`${apiBaseUrl}/game/${eventId}`, {
|
||||
const selectedAccount = accountSelect.value;
|
||||
fetch(`${apiBaseUrl}/game/${eventId}?account=${selectedAccount}`, {
|
||||
headers: { "Authorization": `Bearer ${storedApiKey}` }
|
||||
})
|
||||
.then(response => response.json())
|
||||
|
||||
+96
-30
@@ -165,6 +165,7 @@ def save_cookies(file: str = "cookies.txt"):
|
||||
|
||||
def get_login(
|
||||
local_file: str = "myice.ini",
|
||||
config_section: str = "default",
|
||||
) -> tuple[str, str, int | None, str | None, int | None]:
|
||||
config = configparser.ConfigParser()
|
||||
config.read(
|
||||
@@ -174,22 +175,29 @@ def get_login(
|
||||
local_file,
|
||||
]
|
||||
)
|
||||
if "default" in config.sections():
|
||||
default_config = config["default"]
|
||||
|
||||
username = default_config.get("username")
|
||||
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:
|
||||
if config_section in config.sections():
|
||||
selected_config = config[config_section]
|
||||
elif "default" in config.sections():
|
||||
# Fallback to default section if specified section doesn't exist
|
||||
selected_config = config["default"]
|
||||
print(
|
||||
"Error: please configure username/password in ini file", file=sys.stderr
|
||||
f"Warning: Section '{config_section}' not found, using 'default' section",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
else:
|
||||
print("Error: please configure username/password in ini file", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
username = selected_config.get("username")
|
||||
password = selected_config.get("password")
|
||||
userid = selected_config.getint("userid", fallback=None)
|
||||
token = selected_config.get("token", fallback=None)
|
||||
club_id = selected_config.getint("club_id", fallback=None)
|
||||
|
||||
if not username or not password:
|
||||
print("Error: please configure username/password in ini file", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
return username, password, userid, token, club_id
|
||||
|
||||
|
||||
@@ -202,10 +210,14 @@ def select_club(club_id: int = 172):
|
||||
r.raise_for_status()
|
||||
|
||||
|
||||
def do_login():
|
||||
def do_login(config_section: str = "default"):
|
||||
global session
|
||||
global userid
|
||||
username, password, userid, token, club_id = get_login()
|
||||
username, password, userid_tmp, token, club_id = get_login(
|
||||
config_section=config_section
|
||||
)
|
||||
if userid_tmp is not None:
|
||||
userid = userid_tmp
|
||||
r = session.get("https://app.myice.hockey/", headers={"User-Agent": user_agent})
|
||||
r.raise_for_status()
|
||||
form_data = {
|
||||
@@ -225,6 +237,7 @@ def do_login():
|
||||
)
|
||||
r.raise_for_status()
|
||||
# select the club we want
|
||||
if club_id:
|
||||
select_club(club_id)
|
||||
|
||||
|
||||
@@ -249,15 +262,18 @@ def get_userid():
|
||||
def wrapper_session(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
global session, userid
|
||||
# Extract config_section from kwargs if present
|
||||
config_section = kwargs.get("config_section", "default")
|
||||
|
||||
session = requests.Session()
|
||||
# session.verify = False
|
||||
session.cookies = load_cookies()
|
||||
session.cookies.clear_expired_cookies()
|
||||
if not session.cookies.get("mih_v3_cookname"):
|
||||
print("login...", file=sys.stderr)
|
||||
do_login()
|
||||
do_login(config_section=config_section)
|
||||
save_cookies()
|
||||
_, _, userid, _, _ = get_login()
|
||||
_, _, userid, _, _ = get_login(config_section=config_section)
|
||||
if not userid:
|
||||
print("get userid...", file=sys.stderr)
|
||||
userid = get_userid()
|
||||
@@ -267,7 +283,7 @@ def wrapper_session(func):
|
||||
|
||||
|
||||
@wrapper_session
|
||||
def get_schedule(num_days: int) -> str:
|
||||
def get_schedule(num_days: int, config_section: str = "default") -> str:
|
||||
global session
|
||||
global userid
|
||||
assert session and userid
|
||||
@@ -298,7 +314,7 @@ def get_schedule(num_days: int) -> str:
|
||||
|
||||
|
||||
@wrapper_session
|
||||
def game_pdf(gameid: int, outfile: Path):
|
||||
def game_pdf(gameid: int, outfile: Path, config_section: str = "default"):
|
||||
global session, userid
|
||||
assert session and userid
|
||||
r = session.get(
|
||||
@@ -315,7 +331,7 @@ def game_pdf(gameid: int, outfile: Path):
|
||||
|
||||
|
||||
@wrapper_session
|
||||
def practice_pdf(gameid: int, outfile: Path):
|
||||
def practice_pdf(gameid: int, outfile: Path, config_section: str = "default"):
|
||||
global session, userid
|
||||
assert session and userid
|
||||
r = session.get(
|
||||
@@ -340,11 +356,17 @@ def schedule(
|
||||
),
|
||||
] = None,
|
||||
num_days: Annotated[int, typer.Option("--days")] = 7,
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
"""
|
||||
Fetch schedule as json
|
||||
"""
|
||||
schedule = get_schedule(num_days)
|
||||
schedule = get_schedule(num_days, config_section=config_section)
|
||||
# Sanitize the JSON response using our proven approach
|
||||
sanitized_schedule = sanitize_json_response(schedule)
|
||||
if outfile:
|
||||
@@ -383,6 +405,12 @@ def extract_players(pdf_file: Path) -> List[str]:
|
||||
def get_game_pdf(
|
||||
game_id: Annotated[int, typer.Argument(help="ID of game to gen pdf for")],
|
||||
open_file: Annotated[bool, typer.Option("--open", "-o")] = False,
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
"""
|
||||
Genate the pdf for the game invitation
|
||||
@@ -391,7 +419,7 @@ def get_game_pdf(
|
||||
output_filename = f"game_{game_id}.pdf"
|
||||
else:
|
||||
output_filename = tempfile.NamedTemporaryFile().name
|
||||
game_pdf(game_id, Path(output_filename))
|
||||
game_pdf(game_id, Path(output_filename), config_section=config_section)
|
||||
if open_file:
|
||||
os_open(output_filename)
|
||||
else:
|
||||
@@ -403,12 +431,18 @@ def get_game_pdf(
|
||||
@app.command("practice")
|
||||
def get_practice_pdf(
|
||||
game_id: Annotated[int, typer.Argument(help="ID of practice to gen pdf for")],
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
"""
|
||||
Genate the pdf for the practice invitation
|
||||
"""
|
||||
output_filename = f"practice_{game_id}.pdf"
|
||||
practice_pdf(game_id, Path(output_filename))
|
||||
practice_pdf(game_id, Path(output_filename), config_section=config_section)
|
||||
os_open(output_filename)
|
||||
|
||||
|
||||
@@ -422,6 +456,12 @@ def parse_schedule(
|
||||
schedule_file: Annotated[
|
||||
Path, typer.Option(help="schedule json file to parse")
|
||||
] = Path("schedule.json"),
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
"""
|
||||
Parse schedule.json to look for specific games or practices
|
||||
@@ -471,6 +511,12 @@ def check_with_ai(
|
||||
schedule_file: Annotated[
|
||||
Path, typer.Option(help="schedule json file to parse")
|
||||
] = Path("schedule.json"),
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
"""
|
||||
Search through the schedule with natural language using Infomaniak LLM API
|
||||
@@ -523,10 +569,10 @@ mobile_headers = {
|
||||
}
|
||||
|
||||
|
||||
def mobile_login():
|
||||
def mobile_login(config_section: str = "default"):
|
||||
import base64
|
||||
|
||||
username, password, _, token, club_id = get_login()
|
||||
username, password, _, token, club_id = get_login(config_section=config_section)
|
||||
if token and club_id:
|
||||
return {"id": 0, "token": token, "id_club": club_id}
|
||||
|
||||
@@ -558,23 +604,37 @@ def refresh_data():
|
||||
"https://app.myice.hockey/api/mobilerest/refreshdata",
|
||||
headers=mobile_headers,
|
||||
data=f"token={userdata['token']}&id_club={userdata['id_club']}&language=FR",
|
||||
verify=False,
|
||||
# verify=False,
|
||||
) as r:
|
||||
r.raise_for_status()
|
||||
return r.json()
|
||||
|
||||
|
||||
@app.command("mobile-login")
|
||||
def do_mobile_login():
|
||||
def do_mobile_login(
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
global userdata
|
||||
userdata = mobile_login()
|
||||
userdata = mobile_login(config_section=config_section)
|
||||
print(json.dumps(userdata, indent=2))
|
||||
|
||||
|
||||
@app.command("mobile")
|
||||
def mobile():
|
||||
def mobile(
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
global userdata
|
||||
userdata = mobile_login()
|
||||
userdata = mobile_login(config_section=config_section)
|
||||
games = [x for x in refresh_data().get("club_games")]
|
||||
print(json.dumps(games, indent=2))
|
||||
|
||||
@@ -583,9 +643,15 @@ def mobile():
|
||||
def mobile_game(
|
||||
game_id: Annotated[int, typer.Argument(help="game id")],
|
||||
raw: Annotated[bool, typer.Option(help="display raw output")] = False,
|
||||
config_section: Annotated[
|
||||
str,
|
||||
typer.Option(
|
||||
"--config-section", "-c", help="Configuration section to use from INI file"
|
||||
),
|
||||
] = "default",
|
||||
):
|
||||
global userdata
|
||||
userdata = mobile_login()
|
||||
userdata = mobile_login(config_section=config_section)
|
||||
|
||||
# data = refresh_data()
|
||||
with requests.post(
|
||||
@@ -601,7 +667,7 @@ def mobile_game(
|
||||
"language=FR",
|
||||
]
|
||||
),
|
||||
verify=False,
|
||||
# verify=False,
|
||||
) as r:
|
||||
data = r.json()["eventData"]
|
||||
players = data["convocation"]["available"]
|
||||
|
||||
+57
-6
@@ -74,35 +74,86 @@ async def favico():
|
||||
@app.get("/schedule")
|
||||
async def schedule(
|
||||
headers: Annotated[AuthHeaders, Header()],
|
||||
account: str = "default",
|
||||
):
|
||||
if not headers.authorized():
|
||||
raise HTTPException(401, detail="get out")
|
||||
username, password, userid, existing_token = myice.get_login()
|
||||
username, password, userid, existing_token, club_id = myice.get_login(
|
||||
config_section=account
|
||||
)
|
||||
if existing_token:
|
||||
myice.userdata = {
|
||||
"id": userid,
|
||||
"id_club": 186,
|
||||
"id_club": club_id or 186,
|
||||
"token": existing_token,
|
||||
}
|
||||
else:
|
||||
myice.userdata = myice.mobile_login()
|
||||
myice.userdata = myice.mobile_login(config_section=account)
|
||||
return myice.refresh_data()["club_games"]
|
||||
|
||||
|
||||
@app.get("/accounts")
|
||||
async def accounts(
|
||||
headers: Annotated[AuthHeaders, Header()],
|
||||
):
|
||||
if not headers.authorized():
|
||||
raise HTTPException(401, detail="get out")
|
||||
|
||||
# Import configparser to read the available sections
|
||||
import configparser
|
||||
from pathlib import Path
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config_files = [
|
||||
Path("~/.config/myice.ini").expanduser(),
|
||||
Path("myice.ini"),
|
||||
]
|
||||
|
||||
# Read all config files
|
||||
for config_file in config_files:
|
||||
if config_file.exists():
|
||||
try:
|
||||
config.read(config_file, encoding="utf-8")
|
||||
except Exception:
|
||||
# Try without specifying encoding
|
||||
config.read(config_file)
|
||||
|
||||
# Get all sections (accounts) from the config
|
||||
accounts = []
|
||||
for section in config.sections():
|
||||
if section != "DEFAULT": # Skip DEFAULT section
|
||||
# Capitalize first letter for display
|
||||
label = (
|
||||
section[0].upper() + section[1:]
|
||||
if len(section) > 1
|
||||
else section.upper()
|
||||
)
|
||||
accounts.append({"name": section, "label": label})
|
||||
|
||||
# If no accounts found, return default
|
||||
if not accounts:
|
||||
accounts = [{"name": "default", "label": "Default"}]
|
||||
|
||||
return accounts
|
||||
|
||||
|
||||
@app.get("/game/{game_id}")
|
||||
async def game(
|
||||
headers: Annotated[AuthHeaders, Header()],
|
||||
game_id: int,
|
||||
account: str = "default",
|
||||
):
|
||||
username, password, userid, existing_token = myice.get_login()
|
||||
username, password, userid, existing_token, club_id = myice.get_login(
|
||||
config_section=account
|
||||
)
|
||||
if existing_token:
|
||||
myice.userdata = {
|
||||
"id": userid,
|
||||
"id_club": 186,
|
||||
"id_club": club_id or 186,
|
||||
"token": existing_token,
|
||||
}
|
||||
else:
|
||||
myice.userdata = myice.mobile_login()
|
||||
myice.userdata = myice.mobile_login(config_section=account)
|
||||
|
||||
# data = refresh_data()
|
||||
with requests.post(
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "myice"
|
||||
version = "v0.3.2"
|
||||
version = "v0.4.0"
|
||||
description = "myice parsing"
|
||||
authors = [
|
||||
{ name = "Rene Luria", "email" = "<rene@luria.ch>"},
|
||||
|
||||
Reference in New Issue
Block a user