34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import requests
|
|
from datetime import datetime
|
|
import json
|
|
|
|
SCOREBOARD_DATA_FILE = 'app/data/scoreboard_data.json'
|
|
|
|
def get_scoreboard_data():
|
|
now = datetime.now()
|
|
start_time_evening = now.replace(hour=19, minute=00, second=0, microsecond=0) # 7:00 PM EST
|
|
end_time_evening = now.replace(hour=3, minute=00, second=0, microsecond=0) # 3:00 AM EST
|
|
|
|
if now >= start_time_evening or now < end_time_evening:
|
|
# Use now URL
|
|
nhle_api_url = "https://api-web.nhle.com/v1/score/now"
|
|
|
|
else:
|
|
# Use current data URL
|
|
nhle_api_url = f"https://api-web.nhle.com/v1/score/{now.strftime('%Y-%m-%d')}"
|
|
|
|
response = requests.get(nhle_api_url)
|
|
if response.status_code == 200:
|
|
return response.json()
|
|
else:
|
|
print("Error:", response.status_code)
|
|
|
|
# Store scoreboard data locally
|
|
def store_scoreboard_data():
|
|
scoreboard_data = get_scoreboard_data()
|
|
if scoreboard_data:
|
|
with open(SCOREBOARD_DATA_FILE, 'w') as json_file:
|
|
json.dump(scoreboard_data, json_file)
|
|
return scoreboard_data
|
|
else:
|
|
return None |