fix: improve JSON response handling in API calls

This commit is contained in:
2025-08-19 09:41:28 +02:00
parent c4d9236b16
commit 4b81cc7f9f

View File

@@ -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)