refactor: changes entire project structure
This commit is contained in:
34
app/scoreboard/get_data.py
Normal file
34
app/scoreboard/get_data.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import requests
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
SCOREBOARD_DATA_FILE = 'scoreboard_data.json'
|
||||
|
||||
def get_scoreboard_data():
|
||||
now = datetime.now()
|
||||
start_time_evening = now.replace(hour=23, minute=0, second=0, microsecond=0) # 7:00 PM EST
|
||||
end_time_evening = now.replace(hour=8, minute=0, 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
|
||||
Reference in New Issue
Block a user