crypto symbols and logos added

This commit is contained in:
Neythen
2021-05-24 20:59:42 +01:00
parent 160e5fe7d9
commit 8295ca593e
11 changed files with 90 additions and 61 deletions

View File

@@ -38,6 +38,39 @@ def readCSV(file_path, max_stocks):
f.close()
return symbols, stock_info
def readCryptoCSV(file_path, max_stocks):
symbols = []
names = []
stock_info = {}
f = open(file_path, 'r')
CSV = csv.reader(f)
next(CSV)
i = 0
for row in CSV:
print(row)
if i < max_stocks:
i += 1
try:
symbol, name, current_price, opening_price = row
symbols.append(symbol)
names.append(name)
stock_info[name] = [symbol, current_price, opening_price]
except:
symbol = row[0]
name = row[1]
symbols.append(symbol)
names.append(name)
stock_info[name] = [symbol]
else:
print('max stocks exceeded')
break
f.close()
return names, stock_info
def emptyInfo(symbols, stock_info):
update = False
@@ -137,14 +170,14 @@ def updateStockPricesIEX(symbols):
def updateCrypto(coins):
def updateCrypto(coins, coin_info):
response = coingecko_client.get_price(ids=','.join(coins), vs_currencies = 'usd', include_24hr_change=True)
CSV = open('csv/crypto.csv', 'w+')
CSV.write('name,current,24hr change\n')
CSV.write('symbol,name,current,24hr change\n')
for coin in coins:
CSV.write(coin+ ',' + str(response[coin]['usd']) + ',' + str(response[coin]['usd_24h_change']) + '\n')
CSV.write(coin_info[coin][0] + ',' + coin+ ',' + str(response[coin]['usd']) + ',' + str(response[coin]['usd_24h_change']) + '\n')
CSV.close()
@@ -197,8 +230,10 @@ if __name__ == '__main__':
updateUpdate(NY_time)
while True:
coins, coin_info = readCSV('csv/crypto.csv', max_stocks)
updateCrypto(coins)
coins, coin_info = readCryptoCSV('csv/crypto.csv', max_stocks)
print(coins)
print(coin_info)
updateCrypto(coins, coin_info)
updateNews()