api caller bugfix
This commit is contained in:
parent
bbd40b2160
commit
3220826cdc
144
api_caller.py
144
api_caller.py
@ -76,17 +76,18 @@ def updateStocksFinhubb():
|
||||
|
||||
def updateStocks():
|
||||
|
||||
iexAPIkey = 'pk_d066d39789bd41caac209bca850a35db' #IEX
|
||||
|
||||
max_stocks = 200
|
||||
|
||||
f = open('csv/stocks_settings.json', 'r')
|
||||
all_stocks_settings = json.load(f)
|
||||
f.close()
|
||||
stock_info = all_stocks_settings['symbols']
|
||||
symbols = list(stock_info.keys())
|
||||
print(symbols)
|
||||
try:
|
||||
iexAPIkey = 'pk_d066d39789bd41caac209bca850a35db' #IEX
|
||||
|
||||
max_stocks = 200
|
||||
|
||||
f = open('csv/stocks_settings.json', 'r')
|
||||
all_stocks_settings = json.load(f)
|
||||
f.close()
|
||||
stock_info = all_stocks_settings['symbols']
|
||||
symbols = list(stock_info.keys())
|
||||
print(symbols)
|
||||
|
||||
valid_symbols = []
|
||||
current_prices = []
|
||||
@ -154,42 +155,44 @@ def updateStocks():
|
||||
|
||||
|
||||
def updateCrypto():
|
||||
coingecko_client = CoinGeckoAPI()
|
||||
|
||||
f = open('csv/crypto_settings.json', 'r')
|
||||
all_crypto_settings = json.load(f)
|
||||
f.close()
|
||||
|
||||
coin_info = all_crypto_settings['symbols']
|
||||
symbol_base = list(coin_info.keys())
|
||||
|
||||
symbols = [sb.split(',')[0] for sb in symbol_base]
|
||||
bases = [sb.split(',')[1] for sb in symbol_base]
|
||||
unique_bases = list(set(bases))
|
||||
|
||||
|
||||
|
||||
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+'))
|
||||
|
||||
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)
|
||||
|
||||
#cypto_info['symbol, base'].keys() = ['current','24hr change']
|
||||
try:
|
||||
|
||||
coingecko_client = CoinGeckoAPI()
|
||||
|
||||
f = open('csv/crypto_settings.json', 'r')
|
||||
all_crypto_settings = json.load(f)
|
||||
f.close()
|
||||
|
||||
coin_info = all_crypto_settings['symbols']
|
||||
symbol_base = list(coin_info.keys())
|
||||
|
||||
symbols = [sb.split(',')[0] for sb in symbol_base]
|
||||
bases = [sb.split(',')[1] for sb in symbol_base]
|
||||
unique_bases = list(set(bases))
|
||||
|
||||
|
||||
|
||||
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+'))
|
||||
|
||||
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)
|
||||
@ -216,28 +219,29 @@ def updateCrypto():
|
||||
|
||||
def updateForex():
|
||||
|
||||
f = open('csv/forex_settings.json', 'r')
|
||||
all_forex_settings = json.load(f)
|
||||
f.close()
|
||||
|
||||
forex_info = all_forex_settings['symbols']
|
||||
symbol_base = list(forex_info.keys())
|
||||
|
||||
symbols = [sb.split(',')[0] for sb in symbol_base]
|
||||
bases = [sb.split(',')[1] for sb in symbol_base]
|
||||
unique_bases = list(set(bases))
|
||||
|
||||
all_responses = []
|
||||
|
||||
# get timeseries from two days ago until today in case it hasnt updated for today yet
|
||||
yesterday = datetime.now() - timedelta(1)
|
||||
yesteryesterday = datetime.now() - timedelta(2)
|
||||
|
||||
str_tod = datetime.strftime(datetime.now(), '%Y-%m-%d')
|
||||
str_yest = datetime.strftime(yesterday, '%Y-%m-%d')
|
||||
str_yestyest = datetime.strftime(yesteryesterday, '%Y-%m-%d')
|
||||
|
||||
try:
|
||||
f = open('csv/forex_settings.json', 'r')
|
||||
all_forex_settings = json.load(f)
|
||||
f.close()
|
||||
|
||||
forex_info = all_forex_settings['symbols']
|
||||
symbol_base = list(forex_info.keys())
|
||||
|
||||
symbols = [sb.split(',')[0] for sb in symbol_base]
|
||||
bases = [sb.split(',')[1] for sb in symbol_base]
|
||||
unique_bases = list(set(bases))
|
||||
|
||||
all_responses = []
|
||||
|
||||
# get timeseries from two days ago until today in case it hasnt updated for today yet
|
||||
yesterday = datetime.now() - timedelta(1)
|
||||
yesteryesterday = datetime.now() - timedelta(2)
|
||||
|
||||
str_tod = datetime.strftime(datetime.now(), '%Y-%m-%d')
|
||||
str_yest = datetime.strftime(yesterday, '%Y-%m-%d')
|
||||
str_yestyest = datetime.strftime(yesteryesterday, '%Y-%m-%d')
|
||||
for base in unique_bases:
|
||||
|
||||
url = 'https://api.frankfurter.app/{}..{}?from={}'.format(str_yestyest, str_tod, base)
|
||||
@ -433,13 +437,14 @@ def updateWeather():
|
||||
|
||||
def updateLeagueTables(api_key, league_ids):
|
||||
|
||||
f = open('csv/league_tables.json', 'r')
|
||||
all_settings = json.load(f)
|
||||
f.close()
|
||||
|
||||
leagues = all_settings['leagues'].keys()
|
||||
leagues_info = {}
|
||||
try:
|
||||
f = open('csv/league_tables.json', 'r')
|
||||
all_settings = json.load(f)
|
||||
f.close()
|
||||
|
||||
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)
|
||||
@ -504,11 +509,12 @@ def updateLeagueEvents(api_key, league_ids, time):
|
||||
url = 'https://thesportsdb.com/api/v2/json/{}/livescore.php?l={}'
|
||||
|
||||
|
||||
all_settings = json.load(f)
|
||||
f.close()
|
||||
leagues = all_settings['leagues'].keys()
|
||||
leagues_info = {}
|
||||
|
||||
try:
|
||||
all_settings = json.load(f)
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user