sports api call started

This commit is contained in:
Neythen 2021-06-14 20:36:17 +01:00
parent 3a4347a44a
commit 2d357d9563

View File

@ -199,7 +199,6 @@ def updateNews():
settings = json.load(open('csv/news_settings.json', 'r')) settings = json.load(open('csv/news_settings.json', 'r'))
print(settings) print(settings)
headlines = newsapi.get_top_headlines(**settings) headlines = newsapi.get_top_headlines(**settings)
except: except:
@ -298,7 +297,68 @@ def updateCurrencies(api_key):
print(c_dict) print(c_dict)
json.dump([base, c_dict], open( "csv/currency.json", 'w+' )) json.dump([base, c_dict], open( "csv/currency.json", 'w+' ))
def updateSports():
url = 'https://www.thesportsdb.com/api/v1/json/1/lookuptable.php?l=4328&s=2020-2021' # premier league table
'https://www.thesportsdb.com/api/v1/json/1/eventsnext.php?id=133602' # next five events by team ID (paid) use this for upcoming team games
'https://www.thesportsdb.com/api/v2/json/APIKEY/livescore.php?l=4380' #live scores
r = requests.get(url)
all_data = r.json()
print([all_data['table'][i]['intRank'] for i in range(len(all_data['table']))])
premier_teams = []
print(all_data['table'][0].keys())
for i in range(len(all_data['table'])):
team = {}
team['name'] = all_data['table'][i]['strTeam']
team['wins'] = all_data['table'][i]['intWin']
team['loss'] = all_data['table'][i]['intLoss']
team['draw'] = all_data['table'][i]['intDraw']
team['played'] = all_data['table'][i]['intPlayed']
team['standing'] = all_data['table'][i]['intRank']
team['points'] = all_data['table'][i]['intPoints']
premier_teams.append(team)
json.dump(premier_teams, open( "csv/sports/premier_league/team_stats.json", 'w+' ))
url = 'https://www.thesportsdb.com/api/v1/json/1/eventsseason.php?id=4328&s=2020-2021' # all events in premier league
r = requests.get(url)
all_data = r.json()
print()
print(all_data['events'][0])
#print([all_data['events'][i]['strTimestamp'] for i in range(len(all_data['events']))])
events = []
for i in range(len(all_data['events'][i])):
event = {}
event['date'] = all_data['events'][i]['dateEvent']
event['time'] = all_data['events'][i]['strTime']
event['home_team'] = all_data['events'][i]['strHomeTeam']
event['home_score'] = all_data['events'][i]['intHomeScore']
event['away_team'] = all_data['events'][i]['strAwayTeam']
event['away_score'] = all_data['events'][i]['intAwayScore']
event['round'] = all_data['events'][i]['intRound']
events.append(event)
json.dump(events, open( "csv/sports/premier_league/past_games.json", 'w+' ))
url ='https://www.thesportsdb.com/api/v1/json/1/eventsnextleague.php?id=4328' #next 15 events on the league (premium only)
if __name__ == '__main__': if __name__ == '__main__':
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9') newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
@ -366,6 +426,7 @@ if __name__ == '__main__':
updateCurrencies(currency_key) updateCurrencies(currency_key)
updateNews() updateNews()
updateWeather(weather_location, weather_key) updateWeather(weather_location, weather_key)
updateSports()
NY_time = datetime.now(NY_zone) NY_time = datetime.now(NY_zone)
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks) symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)