fix: improve JSON response handling in API calls
This commit is contained in:
@@ -331,7 +331,7 @@ def get_schedule(num_days: int) -> str:
|
|||||||
# Debug: Save raw response to file for analysis
|
# Debug: Save raw response to file for analysis
|
||||||
# with open("raw_response.txt", "w") as f:
|
# with open("raw_response.txt", "w") as f:
|
||||||
# f.write(r.text)
|
# f.write(r.text)
|
||||||
return r.text
|
return json.loads(sanitize_json_response(r.text))
|
||||||
|
|
||||||
|
|
||||||
@wrapper_session
|
@wrapper_session
|
||||||
@@ -383,13 +383,11 @@ def schedule(
|
|||||||
"""
|
"""
|
||||||
global global_config_section
|
global global_config_section
|
||||||
schedule = get_schedule(num_days)
|
schedule = get_schedule(num_days)
|
||||||
# Sanitize the JSON response using our proven approach
|
|
||||||
sanitized_schedule = sanitize_json_response(schedule)
|
|
||||||
if outfile:
|
if outfile:
|
||||||
with outfile.open("w") as f:
|
with outfile.open("w") as f:
|
||||||
f.write(sanitized_schedule)
|
f.write(json.dumps(schedule))
|
||||||
else:
|
else:
|
||||||
print(sanitized_schedule)
|
print(json.dumps(schedule, indent=2))
|
||||||
|
|
||||||
|
|
||||||
def os_open(file: str) -> None:
|
def os_open(file: str) -> None:
|
||||||
@@ -607,7 +605,7 @@ def refresh_data():
|
|||||||
# verify=False,
|
# verify=False,
|
||||||
) as r:
|
) as r:
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
return r.json()
|
return json.loads(sanitize_json_response(r.text))
|
||||||
|
|
||||||
|
|
||||||
@app.command("mobile-login")
|
@app.command("mobile-login")
|
||||||
@@ -633,7 +631,6 @@ def mobile_game(
|
|||||||
global userdata, global_config_section
|
global userdata, global_config_section
|
||||||
userdata = mobile_login(config_section=global_config_section)
|
userdata = mobile_login(config_section=global_config_section)
|
||||||
|
|
||||||
# data = refresh_data()
|
|
||||||
with requests.post(
|
with requests.post(
|
||||||
"https://app.myice.hockey/api/mobilerest/getevent",
|
"https://app.myice.hockey/api/mobilerest/getevent",
|
||||||
headers=mobile_headers,
|
headers=mobile_headers,
|
||||||
@@ -649,7 +646,8 @@ def mobile_game(
|
|||||||
),
|
),
|
||||||
# verify=False,
|
# verify=False,
|
||||||
) as r:
|
) as r:
|
||||||
data = r.json()["eventData"]
|
data = json.loads(sanitize_json_response(r.text))["eventData"]
|
||||||
|
|
||||||
players = data["convocation"]["available"]
|
players = data["convocation"]["available"]
|
||||||
if raw:
|
if raw:
|
||||||
print(data)
|
print(data)
|
||||||
|
|||||||
Reference in New Issue
Block a user