diff --git a/database_caller.py b/database_caller.py index 6373832..25f1b24 100755 --- a/database_caller.py +++ b/database_caller.py @@ -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() @@ -154,43 +137,28 @@ def updateCrypto(): symbols = [sb.split(',')[0] for sb in symbol_base] bases = [sb.split(',')[1] for sb in symbol_base] unique_bases = list(set(bases)) - - - coins = [] + url = 'https://bm7p954xoh.execute-api.us-east-2.amazonaws.com/default/ScriptsAPI/crypto?symbols=' - # 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+')) - - 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,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) + - 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 + 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']} + + 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 - response = requests.get(url) - data.extend(response.json()) + 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 = 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']} + for d in data: + + 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) + + all_data = r.json() + + + for league in all_data[0].keys(): - 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 - - - - + 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,52 +451,47 @@ 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) - - 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 + url += league + ',' + url = url[:-1] # remove last comma + + r = requests.get(url) + + all_data = r.json() + + print(all_data['NFL'][0]) + + events = [] + + for league in all_data.keys(): + for d in all_data[league]: + event = {} + event['date'] = d['dateEvent'] - - - events = [] - - if not all_data['events'] is None: + if time == 'live': + + event['progess'] = d['strProgress'] + event['status'] = d['strStatus'] + else: + + event['round'] = d['intRound'] + event['time'] = d['strTime'] + event['home_team'] = d['strHomeTeam'] - for i in range(len(all_data['events'])): - event = {} - event['date'] = all_data['events'][i]['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'] - 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'] - - events.append(event) + 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 all_settings['leagues'] = leagues_info 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,24 +503,14 @@ def updateLeagueEvents(api_key, league_ids, time): def updateSports(): #read user settings to decide which sprots to update - api_key = '97436974' + + updateLeagueTables() - - - 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') + #updateLeagueEvents('livescore') + #updateLeagueEvents('past') + #updateLeagueEvents('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): @@ -621,13 +569,6 @@ if __name__ == '__main__': t = time.time() - - updateNews() - sys.exit() - - - - newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9') diff --git a/logos/sports/Premier League/Arsenal.png b/logos/sports/PL/Arsenal.png similarity index 100% rename from logos/sports/Premier League/Arsenal.png rename to logos/sports/PL/Arsenal.png diff --git a/logos/sports/Premier League/Aston Villa.png b/logos/sports/PL/Aston Villa.png similarity index 100% rename from logos/sports/Premier League/Aston Villa.png rename to logos/sports/PL/Aston Villa.png diff --git a/logos/sports/Premier League/Brentford.png b/logos/sports/PL/Brentford.png similarity index 100% rename from logos/sports/Premier League/Brentford.png rename to logos/sports/PL/Brentford.png diff --git a/logos/sports/Premier League/Brighton.png b/logos/sports/PL/Brighton.png similarity index 100% rename from logos/sports/Premier League/Brighton.png rename to logos/sports/PL/Brighton.png diff --git a/logos/sports/Premier League/Burnley.png b/logos/sports/PL/Burnley.png similarity index 100% rename from logos/sports/Premier League/Burnley.png rename to logos/sports/PL/Burnley.png diff --git a/logos/sports/Premier League/Chelsea.png b/logos/sports/PL/Chelsea.png similarity index 100% rename from logos/sports/Premier League/Chelsea.png rename to logos/sports/PL/Chelsea.png diff --git a/logos/sports/Premier League/Crystal Palace.png b/logos/sports/PL/Crystal Palace.png similarity index 100% rename from logos/sports/Premier League/Crystal Palace.png rename to logos/sports/PL/Crystal Palace.png diff --git a/logos/sports/Premier League/Everton.png b/logos/sports/PL/Everton.png similarity index 100% rename from logos/sports/Premier League/Everton.png rename to logos/sports/PL/Everton.png diff --git a/logos/sports/Premier League/Leeds.png b/logos/sports/PL/Leeds.png similarity index 100% rename from logos/sports/Premier League/Leeds.png rename to logos/sports/PL/Leeds.png diff --git a/logos/sports/Premier League/Leicester.png b/logos/sports/PL/Leicester.png similarity index 100% rename from logos/sports/Premier League/Leicester.png rename to logos/sports/PL/Leicester.png diff --git a/logos/sports/Premier League/Liverpool.png b/logos/sports/PL/Liverpool.png similarity index 100% rename from logos/sports/Premier League/Liverpool.png rename to logos/sports/PL/Liverpool.png diff --git a/logos/sports/Premier League/Man City.png b/logos/sports/PL/Man City.png similarity index 100% rename from logos/sports/Premier League/Man City.png rename to logos/sports/PL/Man City.png diff --git a/logos/sports/Premier League/Man United.png b/logos/sports/PL/Man United.png similarity index 100% rename from logos/sports/Premier League/Man United.png rename to logos/sports/PL/Man United.png diff --git a/logos/sports/Premier League/Newcastle.png b/logos/sports/PL/Newcastle.png similarity index 100% rename from logos/sports/Premier League/Newcastle.png rename to logos/sports/PL/Newcastle.png diff --git a/logos/sports/Premier League/Norwich.png b/logos/sports/PL/Norwich.png similarity index 100% rename from logos/sports/Premier League/Norwich.png rename to logos/sports/PL/Norwich.png diff --git a/logos/sports/Premier League/Southampton.png b/logos/sports/PL/Southampton.png similarity index 100% rename from logos/sports/Premier League/Southampton.png rename to logos/sports/PL/Southampton.png diff --git a/logos/sports/Premier League/Tottenham.png b/logos/sports/PL/Tottenham.png similarity index 100% rename from logos/sports/Premier League/Tottenham.png rename to logos/sports/PL/Tottenham.png diff --git a/logos/sports/Premier League/Watford.png b/logos/sports/PL/Watford.png similarity index 100% rename from logos/sports/Premier League/Watford.png rename to logos/sports/PL/Watford.png diff --git a/logos/sports/Premier League/West Ham.png b/logos/sports/PL/West Ham.png similarity index 100% rename from logos/sports/Premier League/West Ham.png rename to logos/sports/PL/West Ham.png diff --git a/logos/sports/Premier League/Wolves.png b/logos/sports/PL/Wolves.png similarity index 100% rename from logos/sports/Premier League/Wolves.png rename to logos/sports/PL/Wolves.png diff --git a/logos/sports/league_logos/Premier League.png b/logos/sports/league_logos/PL.png similarity index 100% rename from logos/sports/league_logos/Premier League.png rename to logos/sports/league_logos/PL.png diff --git a/logos/startup_logo.gif b/logos/startup_logo.gif new file mode 100644 index 0000000..e6a2fb5 Binary files /dev/null and b/logos/startup_logo.gif differ diff --git a/logos/startup_logo_1.gif b/logos/startup_logo_1.gif deleted file mode 100644 index e3924a4..0000000 Binary files a/logos/startup_logo_1.gif and /dev/null differ diff --git a/static/app.js b/static/app.js index 74c0055..fdc1a14 100755 --- a/static/app.js +++ b/static/app.js @@ -1103,6 +1103,7 @@ function getSportsSettings(page) { let title = page.querySelectorAll(".title-select")[0].checked; let leagues_el = page.querySelectorAll(".league-list")[0]; leagues = getListItems(leagues_el); + settings = { title: title, leagues: leagues }; return settings; diff --git a/stockTicker.py b/stockTicker.py index b1b95e8..6980c5b 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -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)) @@ -1747,10 +1748,12 @@ 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') diff --git a/templates/index.html b/templates/index.html index cdb1c9c..58eaf23 100755 --- a/templates/index.html +++ b/templates/index.html @@ -2177,7 +2177,7 @@ - +