sport api and bugfixes
@ -127,23 +127,6 @@ def updateCrypto():
|
||||
try:
|
||||
|
||||
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/crypto?symbols=ETH-BTC'
|
||||
|
||||
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
print(data)
|
||||
|
||||
|
||||
|
||||
stock_info = {}
|
||||
|
||||
for stock in data:
|
||||
stock_info[stock['symbol']] = {'current': stock['price'], 'opening': float(stock['price']) - float(stock['change_since'])}
|
||||
|
||||
|
||||
coingecko_client = CoinGeckoAPI()
|
||||
|
||||
f = open('csv/crypto_settings.json', 'r')
|
||||
all_crypto_settings = json.load(f)
|
||||
f.close()
|
||||
@ -155,42 +138,27 @@ def updateCrypto():
|
||||
bases = [sb.split(',')[1] for sb in symbol_base]
|
||||
unique_bases = list(set(bases))
|
||||
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/crypto?symbols='
|
||||
|
||||
for i,s in enumerate(symbols):
|
||||
url += bases[i] + '-' + s + ','
|
||||
url = url[:-1] #remove last comma
|
||||
print(url)
|
||||
response = requests.get(url)
|
||||
data = response.json()
|
||||
print(data)
|
||||
|
||||
|
||||
coins = []
|
||||
|
||||
# coingecko rate limited me from calling this too often
|
||||
#coin_list = coingecko_client.get_coins_list()
|
||||
#json.dump(coin_list, open('csv/coin_list.json', 'w+'))
|
||||
for i,d in enumerate(data): #TODO get base from the server
|
||||
coin_info[symbol_base[i]] = {'current': d['price'], '24hr_change': d['percent_over_24hr']}
|
||||
|
||||
f = open('coin_list.json', 'r')
|
||||
coin_list = json.load(f)
|
||||
f.close()
|
||||
|
||||
# this might be super slow as coin_list is large
|
||||
for s in symbols:
|
||||
for c in coin_list:
|
||||
if c['symbol'].upper() == s and c['id'] != 'binance-peg-cardano': # hackaround for two coins with symbol ada:
|
||||
coins.append(c['id'])
|
||||
|
||||
crypto_info = {}
|
||||
print(coins)
|
||||
response = coingecko_client.get_price(ids=','.join(coins), vs_currencies = unique_bases, include_24hr_change=True)
|
||||
|
||||
#print(response)
|
||||
|
||||
|
||||
for i,sb in enumerate(symbol_base):
|
||||
#coin_info[name] = [symbol, base]
|
||||
#info = coin_info[coin]
|
||||
#CSV.write(info[0] + ',' + coin + ',' + info[1] + ',' +str(response[coin][info[1]]) + ',' + str(response[coin]['usd_24h_change']) + '\n')
|
||||
crypto_info[sb] = {'current':response[coins[i]][bases[i].lower()], '24hr_change':response[coins[i]]['usd_24h_change']}
|
||||
|
||||
all_crypto_settings['symbols'] = crypto_info
|
||||
all_crypto_settings['symbols'] = coin_info
|
||||
|
||||
json.dump(all_crypto_settings, open('csv/crypto_settings.json', 'w+'))
|
||||
|
||||
except Exception as e:
|
||||
raise e
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
logf.write(str(e))
|
||||
@ -218,24 +186,24 @@ def updateForex():
|
||||
|
||||
targets = ','.join(symbols)
|
||||
|
||||
data = []
|
||||
for base in unique_bases:
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/forex?base={}&targets='.format(base)+targets
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/forex?symbols='
|
||||
|
||||
|
||||
for i,s in enumerate(symbols):
|
||||
url += s + '-' + bases[i] + ','
|
||||
url = url[:-1] #remove last comma
|
||||
|
||||
response = requests.get(url)
|
||||
data.extend(response.json())
|
||||
data = response.json()
|
||||
|
||||
|
||||
|
||||
|
||||
c_dict = {}
|
||||
|
||||
for i, sb in enumerate(symbol_base):
|
||||
|
||||
# check symbol base has data and if so add it to c_dict
|
||||
for d in data:
|
||||
|
||||
if d['uid'] == bases[i] + '/' + symbols[i]:
|
||||
c_dict[sb] = {'current': d['rate'], '24hr_change': d['rate_over_24hr']}
|
||||
c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr']}
|
||||
|
||||
|
||||
|
||||
@ -243,6 +211,7 @@ def updateForex():
|
||||
all_forex_settings['symbols'] = c_dict
|
||||
json.dump(all_forex_settings, open( "csv/forex_settings.json", 'w+' ))
|
||||
except Exception as e:
|
||||
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
logf.write(str(e))
|
||||
@ -408,9 +377,9 @@ def updateWeather():
|
||||
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||
|
||||
|
||||
def updateLeagueTables(api_key, league_ids):
|
||||
|
||||
def updateLeagueTables():
|
||||
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/sports?stats='
|
||||
try:
|
||||
f = open('csv/league_tables.json', 'r')
|
||||
all_settings = json.load(f)
|
||||
@ -418,48 +387,40 @@ def updateLeagueTables(api_key, league_ids):
|
||||
|
||||
leagues = all_settings['leagues'].keys()
|
||||
leagues_info = {}
|
||||
|
||||
for league in leagues:
|
||||
league_id = league_ids[league]
|
||||
url = 'https://www.thesportsdb.com/api/v1/json/{}/lookuptable.php?l={}&s=2020-2021'.format(api_key, league_id)
|
||||
|
||||
url += league + ','
|
||||
url = url[:-1] # remove last comma
|
||||
r = requests.get(url)
|
||||
try:
|
||||
|
||||
all_data = r.json()
|
||||
except Exception as e: # there is no data available
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
logf.write(str(e))
|
||||
logf.write('. file: ' + fname)
|
||||
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||
logf.write('. type: ' + str(exc_type))
|
||||
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||
logf.write(url)
|
||||
continue
|
||||
|
||||
|
||||
for league in all_data[0].keys():
|
||||
|
||||
|
||||
teams = []
|
||||
|
||||
|
||||
for i in range(len(all_data['table'])):
|
||||
for d in all_data[0][league]:
|
||||
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']
|
||||
team['name'] = d['strTeam']
|
||||
team['wins'] = d['intWin']
|
||||
team['loss'] = d['intLoss']
|
||||
team['draw'] = d['intDraw']
|
||||
#team['played'] = d['intPlayed']
|
||||
team['standing'] = d['intRank']
|
||||
#team['points'] = d['intPoints']
|
||||
|
||||
teams.append(team)
|
||||
leagues_info[league] = teams
|
||||
leagues_info[league.upper()] = teams
|
||||
all_settings['leagues'] = leagues_info
|
||||
json.dump(all_settings, open( "csv/league_tables.json".format(league), 'w+' ))
|
||||
except Exception as e:
|
||||
raise e
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
logf.write(str(e))
|
||||
@ -469,17 +430,19 @@ def updateLeagueTables(api_key, league_ids):
|
||||
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||
|
||||
|
||||
def updateLeagueEvents(api_key, league_ids, time):
|
||||
def updateLeagueEvents(time):
|
||||
|
||||
url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/sports?{}='.format(time)
|
||||
|
||||
if time == 'past':
|
||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventspastleague.php?id={}' #last 15 events on the league (premium only)
|
||||
|
||||
f = open('csv/past_games.json')
|
||||
elif time == 'upcoming':
|
||||
url ='https://www.thesportsdb.com/api/v1/json/{}/eventsnextleague.php?id={}' #next 15 events on the league (premium only)
|
||||
|
||||
f = open('csv/upcoming_games.json')
|
||||
elif time == 'live':
|
||||
elif time == 'livescore':
|
||||
f = open('csv/live_games.json')
|
||||
url = 'https://thesportsdb.com/api/v2/json/{}/livescore.php?l={}'
|
||||
|
||||
|
||||
|
||||
|
||||
@ -488,45 +451,39 @@ def updateLeagueEvents(api_key, league_ids, time):
|
||||
f.close()
|
||||
leagues = all_settings['leagues'].keys()
|
||||
leagues_info = {}
|
||||
|
||||
for league in leagues:
|
||||
league_id = league_ids[league]
|
||||
url = url.format(api_key, league_id)
|
||||
url += league + ','
|
||||
url = url[:-1] # remove last comma
|
||||
|
||||
r = requests.get(url)
|
||||
try:
|
||||
|
||||
all_data = r.json()
|
||||
except Exception as e: # there is no data available
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
logf.write(str(e))
|
||||
logf.write('. file: ' + fname)
|
||||
logf.write('. line: ' + str(exc_tb.tb_lineno))
|
||||
logf.write('. type: ' + str(exc_type))
|
||||
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||
logf.write(url)
|
||||
continue
|
||||
|
||||
|
||||
print(all_data['NFL'][0])
|
||||
|
||||
events = []
|
||||
|
||||
if not all_data['events'] is None:
|
||||
|
||||
for i in range(len(all_data['events'])):
|
||||
for league in all_data.keys():
|
||||
for d in all_data[league]:
|
||||
event = {}
|
||||
event['date'] = all_data['events'][i]['dateEvent']
|
||||
event['date'] = d['dateEvent']
|
||||
|
||||
if time == 'live':
|
||||
event['time'] = all_data['events'][i]['strEventTime']
|
||||
event['progess'] = all_data['events'][i]['strProgress']
|
||||
event['status'] = all_data['events'][i]['strStatus']
|
||||
|
||||
event['progess'] = d['strProgress']
|
||||
event['status'] = d['strStatus']
|
||||
else:
|
||||
event['time'] = all_data['events'][i]['strTime']
|
||||
event['round'] = all_data['events'][i]['intRound']
|
||||
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'] = d['intRound']
|
||||
event['time'] = d['strTime']
|
||||
event['home_team'] = d['strHomeTeam']
|
||||
|
||||
event['away_team'] = d['strAwayTeam']
|
||||
|
||||
if time != 'upcoming':
|
||||
event['away_score'] = d['intAwayScore']
|
||||
event['home_score'] = d['intHomeScore']
|
||||
|
||||
events.append(event)
|
||||
leagues_info[league] = events
|
||||
@ -534,6 +491,7 @@ def updateLeagueEvents(api_key, league_ids, time):
|
||||
|
||||
json.dump(all_settings, open( "csv/{}_games.json".format(time), 'w+' ))
|
||||
except Exception as e:
|
||||
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
logf.write(str(e))
|
||||
@ -545,25 +503,15 @@ def updateLeagueEvents(api_key, league_ids, time):
|
||||
|
||||
def updateSports():
|
||||
#read user settings to decide which sprots to update
|
||||
api_key = '97436974'
|
||||
|
||||
updateLeagueTables()
|
||||
|
||||
#updateLeagueEvents('livescore')
|
||||
#updateLeagueEvents('past')
|
||||
#updateLeagueEvents('upcoming')
|
||||
|
||||
|
||||
|
||||
league_ids = {'Premier League':'4328', 'NHL':'4380', 'NBA':'4387', 'NFL':'4391'}
|
||||
updateLeagueTables(api_key, league_ids)
|
||||
|
||||
updateLeagueEvents(api_key, league_ids, 'live')
|
||||
updateLeagueEvents(api_key, league_ids, 'past')
|
||||
updateLeagueEvents(api_key, league_ids, 'upcoming')
|
||||
|
||||
|
||||
|
||||
'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
|
||||
|
||||
#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/v2/json/{}/livescore.php?l=4380'.format(api_key) #live scores
|
||||
|
||||
|
||||
def checkStocks(last_update, update_frequency):
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
@ -621,13 +569,6 @@ if __name__ == '__main__':
|
||||
t = time.time()
|
||||
|
||||
|
||||
|
||||
updateNews()
|
||||
sys.exit()
|
||||
|
||||
|
||||
|
||||
|
||||
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.6 KiB After Width: | Height: | Size: 2.6 KiB |
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
logos/startup_logo.gif
Normal file
After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 50 KiB |
@ -1104,6 +1104,7 @@ function getSportsSettings(page) {
|
||||
let leagues_el = page.querySelectorAll(".league-list")[0];
|
||||
leagues = getListItems(leagues_el);
|
||||
|
||||
|
||||
settings = { title: title, leagues: leagues };
|
||||
return settings;
|
||||
}
|
||||
|
@ -1688,6 +1688,7 @@ class StockTicker():
|
||||
img = img.crop((0,0,x_offset ,32))
|
||||
imgs.append(img)
|
||||
except Exception as e:
|
||||
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
self.logf.write(str(e))
|
||||
@ -1748,9 +1749,11 @@ class StockTicker():
|
||||
|
||||
logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo']))
|
||||
|
||||
|
||||
img.paste(logo, (x_offset, 0))
|
||||
x_offset += logo.size[0] + 2
|
||||
except Exception as e:
|
||||
|
||||
print('no logo for:', team['name'])
|
||||
|
||||
|
||||
@ -1758,7 +1761,7 @@ class StockTicker():
|
||||
wins_timage = self.textImage('Wins:' + team['wins'], small_font, r = 0, g = 255, b = 0)
|
||||
loss_timage = self.textImage('Losses:' + team['loss'], small_font, r = 255, g = 0, b = 0)
|
||||
draw_timage = self.textImage('Draws:' + team['draw'], small_font, r = 0, g = 0, b = 255)
|
||||
points_timage = self.textImage('Points:' + team['points'], small_font, r = 255, g = 255, b = 255)
|
||||
#points_timage = self.textImage('Points:' + team['points'], small_font, r = 255, g = 255, b = 255)
|
||||
standing_timage = self.textImage('Standing:' + team['standing'], small_font, r = 255, g = 255, b = 255)
|
||||
|
||||
|
||||
@ -1769,15 +1772,17 @@ class StockTicker():
|
||||
img.paste(draw_timage, (x_offset, 26))
|
||||
|
||||
x_offset += max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0])
|
||||
img.paste(points_timage, (x_offset, 14))
|
||||
#img.paste(points_timage, (x_offset, 14))
|
||||
img.paste(standing_timage, (x_offset, 22))
|
||||
|
||||
x_offset += max(points_timage.size[0], standing_timage.size[0]) + buff_size
|
||||
#x_offset += max(points_timage.size[0], standing_timage.size[0]) + buff_size
|
||||
x_offset += standing_timage.size[0] + buff_size
|
||||
|
||||
|
||||
img = img.crop((0,0,x_offset ,32))
|
||||
imgs.append(img)
|
||||
except Exception as e:
|
||||
raise e
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
|
||||
self.logf.write(str(e))
|
||||
@ -2715,7 +2720,7 @@ if __name__ == '__main__':
|
||||
stock_ticker.logf = log
|
||||
|
||||
start_image = Image.open('./logos/startup_logo.png')
|
||||
start_GIF = Image.open('./logos/startup_logo_1.gif')
|
||||
start_GIF = Image.open('./logos/startup_logo.gif')
|
||||
|
||||
msg = getInput()
|
||||
if msg =='*':
|
||||
@ -2735,7 +2740,7 @@ if __name__ == '__main__':
|
||||
#stock_ticker.process_msg('G')
|
||||
#stock_ticker.process_msg('f')
|
||||
#stock_ticker.process_msg('W')
|
||||
#stock_ticker.process_msg('A')
|
||||
stock_ticker.process_msg('A')
|
||||
|
||||
|
||||
|
||||
|
@ -2177,7 +2177,7 @@
|
||||
<option>NFL</option>
|
||||
<option>NBA</option>
|
||||
<option>NHA</option>
|
||||
<option>Premier League</option>
|
||||
<option>PL</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-auto">
|
||||
|