professional display demo

This commit is contained in:
Neythen
2021-07-08 19:42:21 +01:00
parent c2ff751f83
commit 711466424c
538 changed files with 341 additions and 159 deletions

View File

@@ -42,7 +42,7 @@ def readCSV(file_path, max_stocks):
symbols.append(symbol)
stock_info[symbol] = []
else:
print('max stocks exceeded')
break
f.close()
@@ -60,7 +60,7 @@ def readCryptoCSV(file_path, max_crypto):
i = 0
unique_bases = []
for row in CSV:
print(row)
if i < max_crypto:
i += 1
@@ -80,7 +80,7 @@ def readCryptoCSV(file_path, max_crypto):
names.append(name)
stock_info[name] = [symbol, base]
else:
print(i, max_crypto, 'max crypto exceeded')
break
f.close()
@@ -122,7 +122,7 @@ def updateStockPricesFinhubb():
CSV.write(symbol + ',' + str(current_prices[i]) + ',' + str(opening_prices[i]) + '\n')
CSV.close()
print('API called successfully')
except Exception as e:
@@ -133,7 +133,7 @@ def updateStockPricesFinhubb():
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])))
print(e)
def updateStockPrices():
@@ -143,35 +143,12 @@ def updateStockPrices():
max_stocks = 200
symbols, stock_info = readCSV('csv/tickers.csv', max_stocks)
try:
'''
symbols_str = ','.join(symbols)
print(symbols)
print(symbols_str)
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
lastEndpoint = '/tops/last'
querystring = '?symbols=' + symbols_str +'&token='+iexAPIkey
last_request_url = host + lastEndpoint + querystring
print('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
print('Request URL = ' + last_request_url)
last_response = requests.get(last_request_url)
print('done')
if last_response.status_code == 200:
print('last success')
for stock in last_response.json():
current_prices.append(stock['price'])
'''
current_prices = []
opening_prices = []
for symbol in symbols:
print(symbol)
method = 'GET'
host = 'https://cloud.iexapis.com/stable'
@@ -179,20 +156,12 @@ def updateStockPrices():
querystring = '?chartIEXOnly=true&token='+iexAPIkey
intraday_request_url = host + intradayEndpoint + querystring
print('\nBEGIN REQUEST++++++++++++++++++++++++++++++++++++')
print('Request URL = ' + intraday_request_url)
intraday_response = requests.get(intraday_request_url)
print('\nRESPONSE++++++++++++++++++++++++++++++++++++')
print('Response code: \n',intraday_response)
#print(intraday_response.text)
for i in range(len(intraday_response.json())):
opn = intraday_response.json()[i]['open']
print(opn)
if opn is not None:
break
for i in range(len(intraday_response.json())-1, 0, -1):
@@ -203,12 +172,6 @@ def updateStockPrices():
opening_prices.append(opn)
current_prices.append(current)
print(opn, current)
'''
for time_point in intraday_response.json():
print(time_point['date'])
print(time_point['open'])
'''
CSV = open('csv/tickers.csv', 'w+')
CSV.write('name,current,opening\n')
@@ -237,13 +200,11 @@ def updateCrypto():
coins, coin_info, unique_bases = readCryptoCSV('csv/crypto.csv', max_crypto)
try:
response = coingecko_client.get_price(ids=','.join(coins), vs_currencies = unique_bases, include_24hr_change=True)
print(response)
CSV = open('csv/crypto.csv', 'w+')
CSV.write('symbol,name,base,current,24hr change\n')
for coin in coins:
info = coin_info[coin]
print(info)
CSV.write(info[0] + ',' + coin + ',' + info[1] + ',' +str(response[coin][info[1]]) + ',' + str(response[coin]['usd_24h_change']) + '\n')
CSV.close()
@@ -255,7 +216,6 @@ def updateCrypto():
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])))
print(e)
def updateNews():
@@ -295,7 +255,7 @@ def updateNews():
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])))
print(e)
def updateWeather():
max_cities = 30
@@ -371,7 +331,6 @@ def updateWeather():
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])))
print(e)
def updateForex():
@@ -410,7 +369,7 @@ def updateForex():
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])))
print(e)
def updateLeagueTable(api_key, league_id):
try:
@@ -427,8 +386,7 @@ def updateLeagueTable(api_key, league_id):
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']
@@ -459,7 +417,7 @@ def updateLeagueTable(api_key, league_id):
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])))
print(e)
def updateLeagueEvents(api_key, league_id, time):
@@ -516,7 +474,7 @@ def updateLeagueEvents(api_key, league_id, time):
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])))
print(e)
def updateSports():
#read user settings to decide which sprots to update
@@ -533,7 +491,7 @@ def updateSports():
updateLeagueEvents(api_key, i, 'future')
print('sports updated')
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
@@ -585,14 +543,7 @@ if __name__ == '__main__':
logf = open("log.txt", "w")
t = time.time()
'''
updateStockPrices()
print('finnhub:',time.time() -t)
t = time.time()
updateStockPricesIEX()
print('iex:', time.time() -t)
sys.exit()
'''
max_stocks = 200
max_crypto = 100
@@ -714,6 +665,6 @@ if __name__ == '__main__':
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])))
print(e)