sports api call started
This commit is contained in:
parent
3a4347a44a
commit
2d357d9563
@ -198,8 +198,7 @@ def updateNews():
|
||||
#load user settings
|
||||
|
||||
settings = json.load(open('csv/news_settings.json', 'r'))
|
||||
|
||||
|
||||
|
||||
print(settings)
|
||||
headlines = newsapi.get_top_headlines(**settings)
|
||||
except:
|
||||
@ -298,7 +297,68 @@ def updateCurrencies(api_key):
|
||||
print(c_dict)
|
||||
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__':
|
||||
|
||||
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
|
||||
|
||||
|
||||
@ -366,6 +426,7 @@ if __name__ == '__main__':
|
||||
updateCurrencies(currency_key)
|
||||
updateNews()
|
||||
updateWeather(weather_location, weather_key)
|
||||
updateSports()
|
||||
|
||||
NY_time = datetime.now(NY_zone)
|
||||
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
|
||||
|
Loading…
Reference in New Issue
Block a user