added NHL support
This commit is contained in:
@@ -297,22 +297,23 @@ def updateCurrencies(api_key):
|
||||
print(c_dict)
|
||||
json.dump([base, c_dict], open( "csv/currency.json", 'w+' ))
|
||||
|
||||
|
||||
def updateSports(api_key):
|
||||
url = 'https://www.thesportsdb.com/api/v1/json/{}/lookuptable.php?l=4328&s=2020-2021'.format(api_key) # premier league table
|
||||
'https://www.thesportsdb.com/api/v1/json/{}/eventsnext.php?id=133602'.format(api_key) # next five events by team ID (paid) use this for upcoming team games
|
||||
|
||||
def updateLeagueTable(api_key, league_id):
|
||||
url = 'https://www.thesportsdb.com/api/v1/json/{}/lookuptable.php?l={}&s=2020-2021'.format(api_key, league_id)
|
||||
|
||||
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())
|
||||
print(all_data['table'])
|
||||
|
||||
for i in range(len(all_data['table'])):
|
||||
team = {}
|
||||
|
||||
if all_data['table'][i]['strTeam'] == "Calgary Flames":
|
||||
print(all_data['table'][i]['dateUpdated'], all_data['table'][i]['intPoints'])
|
||||
|
||||
team['name'] = all_data['table'][i]['strTeam']
|
||||
team['wins'] = all_data['table'][i]['intWin']
|
||||
team['loss'] = all_data['table'][i]['intLoss']
|
||||
@@ -322,44 +323,81 @@ def updateSports(api_key):
|
||||
team['points'] = all_data['table'][i]['intPoints']
|
||||
|
||||
premier_teams.append(team)
|
||||
|
||||
json.dump(premier_teams, open( "csv/sports/premier_league/team_stats.json", 'w+' ))
|
||||
|
||||
|
||||
if league_id == '4328':
|
||||
league = 'premier_league'
|
||||
elif league_id == '4380':
|
||||
league = 'NHL'
|
||||
|
||||
#url = 'https://www.thesportsdb.com/api/v1/json/{}/eventsseason.php?id=4328&s=2020-2021'.format(api_key) # all past events in premier league
|
||||
json.dump(premier_teams, open( "csv/sports/{}/team_stats.json".format(league), 'w+' ))
|
||||
|
||||
def updateLeagueEvents(api_key, league_id, time):
|
||||
|
||||
if time == 'past':
|
||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventspastleague.php?id={}'.format(api_key, league_id) #last 15 events on the league (premium only)
|
||||
else:
|
||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventsnextleague.php?id={}'.format(api_key, league_id) #next 15 events on the league (premium only)
|
||||
|
||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventspastleague.php?id=4328'.format(api_key) #last 15 events on the league (premium only)
|
||||
|
||||
print(url)
|
||||
r = requests.get(url)
|
||||
all_data = r.json()
|
||||
|
||||
print()
|
||||
print(all_data['events'][0])
|
||||
#print(all_data['events'][0].keys())
|
||||
#print([all_data['events'][i]['strTimestamp'] for i in range(len(all_data['events']))])
|
||||
|
||||
events = []
|
||||
|
||||
for i in range(len(all_data['events'])):
|
||||
event = {}
|
||||
event['date'] = all_data['events'][i]['dateEvent']
|
||||
print(event['date'])
|
||||
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)
|
||||
if not all_data['events'] is None:
|
||||
for i in range(len(all_data['events'])):
|
||||
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)
|
||||
|
||||
|
||||
if league_id == '4328':
|
||||
league = 'premier_league'
|
||||
elif league_id == '4380':
|
||||
league = 'NHL'
|
||||
|
||||
json.dump(events, open( "csv/sports/{}/{}_games.json".format(league, time), 'w+' ))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def updateSports(api_key):
|
||||
prem_id = '4328' #prem
|
||||
NHL_id = '4380'
|
||||
|
||||
#updateLeagueTable(api_key, prem_id) #prem
|
||||
updateLeagueEvents(api_key, prem_id, 'past')
|
||||
updateLeagueEvents(api_key, NHL_id, 'future')
|
||||
|
||||
updateLeagueTable(api_key, NHL_id)
|
||||
updateLeagueTable(api_key, prem_id)
|
||||
|
||||
|
||||
|
||||
'https://www.thesportsdb.com/api/v1/json/{}/eventsnext.php?id=133602'.format(api_key) # next five events by team ID (paid) use this for upcoming team games
|
||||
|
||||
|
||||
|
||||
|
||||
json.dump(events, open( "csv/sports/premier_league/past_games.json", 'w+' ))
|
||||
#url = 'https://www.thesportsdb.com/api/v1/json/{}/eventsseason.php?id=4328&s=2020-2021'.format(api_key) # all past events in premier league
|
||||
|
||||
|
||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventsnextleague.php?id=4328'.format(api_key) #next 15 events on the league (premium only)
|
||||
|
||||
url = 'https://www.thesportsdb.com/api/v2/json/{}/livescore.php?l=4380'.format(api_key) #live scores
|
||||
print(all_data)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user