From 4b81cc7f9f38af20f13546b974a5f36e2a6aa6ae Mon Sep 17 00:00:00 2001 From: Rene Luria Date: Tue, 19 Aug 2025 09:41:28 +0200 Subject: [PATCH] fix: improve JSON response handling in API calls --- myice/myice.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/myice/myice.py b/myice/myice.py index d2aaade..6c6a5bf 100755 --- a/myice/myice.py +++ b/myice/myice.py @@ -331,7 +331,7 @@ def get_schedule(num_days: int) -> str: # Debug: Save raw response to file for analysis # with open("raw_response.txt", "w") as f: # f.write(r.text) - return r.text + return json.loads(sanitize_json_response(r.text)) @wrapper_session @@ -383,13 +383,11 @@ def schedule( """ global global_config_section schedule = get_schedule(num_days) - # Sanitize the JSON response using our proven approach - sanitized_schedule = sanitize_json_response(schedule) if outfile: with outfile.open("w") as f: - f.write(sanitized_schedule) + f.write(json.dumps(schedule)) else: - print(sanitized_schedule) + print(json.dumps(schedule, indent=2)) def os_open(file: str) -> None: @@ -607,7 +605,7 @@ def refresh_data(): # verify=False, ) as r: r.raise_for_status() - return r.json() + return json.loads(sanitize_json_response(r.text)) @app.command("mobile-login") @@ -633,7 +631,6 @@ def mobile_game( global userdata, global_config_section userdata = mobile_login(config_section=global_config_section) - # data = refresh_data() with requests.post( "https://app.myice.hockey/api/mobilerest/getevent", headers=mobile_headers, @@ -649,7 +646,8 @@ def mobile_game( ), # verify=False, ) as r: - data = r.json()["eventData"] + data = json.loads(sanitize_json_response(r.text))["eventData"] + players = data["convocation"]["available"] if raw: print(data)