bug fix and professional display started
This commit is contained in:
@@ -29,6 +29,7 @@ def readCSV(file_path, max_stocks):
|
||||
next(CSV)
|
||||
i = 0
|
||||
for row in CSV:
|
||||
|
||||
if i < max_stocks:
|
||||
i += 1
|
||||
|
||||
@@ -60,26 +61,26 @@ def readCryptoCSV(file_path, max_crypto):
|
||||
unique_bases = []
|
||||
for row in CSV:
|
||||
print(row)
|
||||
if i >= max_stocks:
|
||||
break
|
||||
i += 1
|
||||
if i < max_crypto:
|
||||
|
||||
i += 1
|
||||
|
||||
try:
|
||||
symbol, name, base, current_price, opening_price = row
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base, current_price, opening_price]
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
except:
|
||||
symbol, name, base = row
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base]
|
||||
try:
|
||||
symbol, name, base, current_price, opening_price = row
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base, current_price, opening_price]
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
except:
|
||||
symbol, name, base = row
|
||||
if base not in unique_bases:
|
||||
unique_bases.append(base)
|
||||
symbols.append(symbol)
|
||||
names.append(name)
|
||||
stock_info[name] = [symbol, base]
|
||||
else:
|
||||
print('max stocks exceeded')
|
||||
print(i, max_crypto, 'max crypto exceeded')
|
||||
break
|
||||
|
||||
f.close()
|
||||
@@ -218,7 +219,7 @@ def updateStockPricesIEX():
|
||||
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])))
|
||||
raise e
|
||||
|
||||
sys.exit()
|
||||
|
||||
|
||||
@@ -228,7 +229,7 @@ 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')
|
||||
|
||||
@@ -464,7 +465,7 @@ def updateLeagueEvents(api_key, league_id, time):
|
||||
all_data = r.json()
|
||||
|
||||
print()
|
||||
#print(all_data['events'][0].keys())
|
||||
print(all_data['events'])
|
||||
#print([all_data['events'][i]['strTimestamp'] for i in range(len(all_data['events']))])
|
||||
|
||||
events = []
|
||||
@@ -519,13 +520,13 @@ def updateSports():
|
||||
NBA_id = '4387' #prem
|
||||
NFL_id = '4391'
|
||||
|
||||
for i in [NHL_id]:
|
||||
for i in [NHL_id, prem_id]:
|
||||
updateLeagueEvents(api_key, i, 'live')
|
||||
updateLeagueEvents(api_key, i, 'past')
|
||||
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
|
||||
@@ -588,9 +589,11 @@ if __name__ == '__main__':
|
||||
max_stocks = 200
|
||||
max_crypto = 100
|
||||
|
||||
|
||||
|
||||
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
|
||||
|
||||
update_frequencies = {'stocks':2, 'crypto':10, 'news':120, 'weather': 10} #minutes
|
||||
update_frequencies = {'stocks':2, 'crypto':10, 'news':120, 'weather': 10, 'sports': 120} #minutes
|
||||
|
||||
NY_zone = pytz.timezone('America/New_York')
|
||||
CET_zone = pytz.timezone('Europe/Berlin')
|
||||
@@ -614,7 +617,6 @@ if __name__ == '__main__':
|
||||
t = time.time()
|
||||
|
||||
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
||||
@@ -631,7 +633,7 @@ if __name__ == '__main__':
|
||||
|
||||
# crypto
|
||||
crypto_time = datetime.strptime(last_updates['crypto'], "%d/%m/%Y %H:%M:%S")
|
||||
crypto_frequency = update_frequencies['crypto']
|
||||
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - crypto_time).total_seconds()/60 #minutes
|
||||
@@ -643,7 +645,7 @@ if __name__ == '__main__':
|
||||
|
||||
# weather
|
||||
weather_time = datetime.strptime(last_updates['weather'], "%d/%m/%Y %H:%M:%S")
|
||||
weather_frequency = update_frequencies['weather']
|
||||
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - weather_time).total_seconds()/60 #minutes
|
||||
@@ -655,7 +657,7 @@ if __name__ == '__main__':
|
||||
|
||||
# news
|
||||
news_time = datetime.strptime(last_updates['news'], "%d/%m/%Y %H:%M:%S")
|
||||
news_frequency = update_frequencies['news']
|
||||
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - news_time).total_seconds()/60 #minutes
|
||||
@@ -664,6 +666,17 @@ if __name__ == '__main__':
|
||||
updateNews()
|
||||
last_updates['news'] = news_time
|
||||
|
||||
# sports
|
||||
sports_time = datetime.strptime(last_updates['sports'], "%d/%m/%Y %H:%M:%S")
|
||||
|
||||
|
||||
NY_time = datetime.now(NY_zone).replace(tzinfo=None)
|
||||
diff = (NY_time - sports_time).total_seconds()/60 #minutes
|
||||
if diff >= update_frequencies['sports']:
|
||||
sports_time = NY_time.strftime("%d/%m/%Y %H:%M:%S")
|
||||
updateSports()
|
||||
last_updates['sports'] = sports_time
|
||||
|
||||
#forex updates once every 24hours at 1700 CET
|
||||
|
||||
# update if last update was before the previous days closing
|
||||
@@ -676,6 +689,10 @@ if __name__ == '__main__':
|
||||
last_updates['forex'] = forex_time
|
||||
updateForex()
|
||||
|
||||
f = open('csv/last_updates.json', 'w+')
|
||||
json.dump(last_updates, f)
|
||||
f.close()
|
||||
|
||||
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]
|
||||
|
Reference in New Issue
Block a user