-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_fetch.py
More file actions
26 lines (22 loc) · 921 Bytes
/
api_fetch.py
File metadata and controls
26 lines (22 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests
import json
from pathlib import Path
output_file = "data/matches_scorecard.json"
def fetch_live_scorecards():
try:
response = requests.get("YOUR_API_ENDPOINT")
if response.status_code == 200:
data = response.json()
if data and "matches" in data and len(data["matches"]) > 0:
# Save only if data exists
with open(output_file, "w", encoding="utf-8") as f:
json.dump(data, f, indent=4)
print("✅ Scorecards updated.")
else:
print("⚠️ API returned no data. Existing JSON kept.")
else:
print(f"❌ API Error {response.status_code}. Existing JSON kept.")
except Exception as e:
print(f"❌ Exception occurred: {e}. Existing JSON kept.")
if __name__ == "__main__":
fetch_live_scorecards()