individual sports api calls

This commit is contained in:
Neythen Treloar 2022-03-07 17:34:24 +00:00
parent e5784af50f
commit 4ba23566bc
2 changed files with 65 additions and 11 deletions

View File

@ -448,7 +448,7 @@ def updateLeagueTables(api_key, logf):
def updateLeagueEvents(api_key, time, logf):
print('LEAGUE EVENTS')
print('LEAGUE EVENTS', time)
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/sports?{}='.format(time)
if time == 'past':
@ -657,10 +657,14 @@ if __name__ == '__main__':
f.close()
except:
last_updates = {"stocks": {True, "27/06/2021 07:05:39"}, "crypto": {True, "27/06/2021 07:05:39"}, "news": {True, "27/06/2021 07:05:39"}, "weather": {True, "27/06/2021 07:05:39"},"forex": {True, "27/06/2021 07:05:39"}, "sports": {True, "27/06/2021 07:05:39"}}
last_updates = {"stocks": {"time": "06/03/2022 04:12:09", "force": True}, "crypto": {"time": "06/03/2022 04:10:39", "force": True},
"news": {"time": "06/03/2022 04:07:09", "force": True}, "weather": {"time": "06/03/2022 04:08:20", "force": True},
"forex": {"time": "06/03/2022 03:54:02", "force": True}, "sports_l": {"time": "06/03/2022 04:10:09", "force": True},
"sports_p": {"time": "06/03/2022 04:10:09", "force": True},
"sports_u": {"time": "06/03/2022 04:10:09", "force": True},"sports_t": {"time": "06/03/2022 04:10:09", "force": True}}
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
@ -740,19 +744,65 @@ if __name__ == '__main__':
update_process = Process(target = updateNews, args = (api_key,logf))
update_process.start()
update_processes.append(update_process)
# sports
sports_time = datetime.strptime(last_updates['sports']['time'], "%d/%m/%Y %H:%M:%S")
# sports upcoming
sports_time = datetime.strptime(last_updates['sports_u']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - sports_time).total_seconds()/60 #minutes
if last_updates['sports']['force'] or diff >= update_frequencies['sports']:# or msg == 'S':
if last_updates['sports_u']['force'] or diff >= update_frequencies['sports']:# or msg == 'S':
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
#updateSports(api_key)
last_updates['sports']['time'] = sports_time
last_updates['sports']['force'] = False
update_process = Process(target = updateSports, args = (api_key,logf))
last_updates['sports_u']['time'] = sports_time
last_updates['sports_u']['force'] = False
update_process = Process(target = updateLeagueEvents, args = (api_key,'upcoming',logf))
update_process.start()
update_processes.append(update_process)
# sports live
sports_time = datetime.strptime(last_updates['sports_l']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - sports_time).total_seconds()/60 #minutes
if last_updates['sports_l']['force'] or diff >= update_frequencies['sports']:# or msg == 'S':
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
#updateSports(api_key)
last_updates['sports_l']['time'] = sports_time
last_updates['sports_l']['force'] = False
update_process = Process(target = updateLeagueEvents, args = (api_key, 'livescore',logf))
update_process.start()
update_processes.append(update_process)
# sports past
sports_time = datetime.strptime(last_updates['sports_p']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - sports_time).total_seconds()/60 #minutes
if last_updates['sports_p']['force'] or diff >= update_frequencies['sports']:# or msg == 'S':
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
#updateSports(api_key)
last_updates['sports_p']['time'] = sports_time
last_updates['sports_p']['force'] = False
update_process = Process(target = updateLeagueEvents, args = (api_key,'past',logf))
update_process.start()
update_processes.append(update_process)
# sports table
sports_time = datetime.strptime(last_updates['sports_t']['time'], "%d/%m/%Y %H:%M:%S")
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
diff = (NY_time - sports_time).total_seconds()/60 #minutes
if last_updates['sports_t']['force'] or diff >= update_frequencies['sports']:# or msg == 'S':
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
#updateSports(api_key)
last_updates['sports_t']['time'] = sports_time
last_updates['sports_t']['force'] = False
update_process = Process(target = updateLeagueTables, args = (api_key,logf))
update_process.start()
update_processes.append(update_process)
#forex updates once every 24hours at 1700 CET

View File

@ -671,12 +671,16 @@ def save_sports_settings(input_settings):
if feature == 'Sports (Upcoming Games)':
filename = 'upcoming_games.json'
update_key = 'sports_u'
elif feature == 'Sports (Past Games)':
filename = 'past_games.json'
update_key = 'sports_p'
elif feature == 'Sports (Live Games)':
filename = 'live_games.json'
update_key = 'sports_l'
elif feature == 'Sports (Team Stats)':
filename = 'league_tables.json'
update_key = 'sports_t'
current_settings = json.load(open('csv/' + filename, 'r'))
@ -697,7 +701,7 @@ def save_sports_settings(input_settings):
if any([current_settings['leagues'][k] == [] for k in input_settings['leagues']]):
last_updates['sports']['force'] = True
last_updates[update_key]['force'] = True
f = open('csv/last_updates.json', 'w+')
json.dump(last_updates, f)