human_formatize volume
This commit is contained in:
parent
07149aa6df
commit
206fd96dcd
@ -146,6 +146,15 @@ def getCookiesnCrumb():
|
||||
f.write(crumb)
|
||||
|
||||
|
||||
def human_format(num):
|
||||
num = float('{:.3g}'.format(num))
|
||||
magnitude = 0
|
||||
while abs(num) >= 1000:
|
||||
magnitude += 1
|
||||
num /= 1000.0
|
||||
return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])
|
||||
|
||||
|
||||
def updateStocks(api_key, logf):
|
||||
|
||||
try:
|
||||
@ -177,7 +186,7 @@ def updateStocks(api_key, logf):
|
||||
if len(data) > 0:
|
||||
for symbol in symbols:
|
||||
try:
|
||||
stock_info[data[symbol]['quote']['symbol']] = {'current': data[symbol]['quote']['latestPrice'], 'change': data[symbol]['quote']['change'], 'percent_change':data[symbol]['quote']['changePercent'] * 100, 'day_low':data[symbol]['quote']['low'], 'day_high':data[symbol]['quote']['high'], 'volume':data[symbol]['quote']['latestVolume']}
|
||||
stock_info[data[symbol]['quote']['symbol']] = {'current': data[symbol]['quote']['latestPrice'], 'change': data[symbol]['quote']['change'], 'percent_change':data[symbol]['quote']['changePercent'] * 100, 'day_low':data[symbol]['quote']['low'], 'day_high':data[symbol]['quote']['high'], 'volume':human_format(data[symbol]['quote']['latestVolume'])}
|
||||
except:
|
||||
pass
|
||||
all_stocks_settings['symbols'] = stock_info
|
||||
@ -216,7 +225,7 @@ def updateStocks(api_key, logf):
|
||||
try:
|
||||
for stock in data['quoteResponse']['result']:
|
||||
if stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B') == symbol:
|
||||
stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')] = {'current': stock['regularMarketPrice'], 'change': stock['regularMarketChange'], 'percent_change':stock['regularMarketChangePercent'], 'day_low': stock['regularMarketDayLow'], 'day_high': stock['regularMarketDayHigh'], 'volume': stock['regularMarketVolume']}
|
||||
stock_info[stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B')] = {'current': stock['regularMarketPrice'], 'change': stock['regularMarketChange'], 'percent_change':stock['regularMarketChangePercent'], 'day_low': stock['regularMarketDayLow'], 'day_high': stock['regularMarketDayHigh'], 'volume': human_format(stock['regularMarketVolume'])}
|
||||
except:
|
||||
pass
|
||||
all_stocks_settings['symbols'] = stock_info
|
||||
@ -366,15 +375,6 @@ def updateCommodities(api_key, logf):
|
||||
#logf.close()
|
||||
|
||||
|
||||
def human_format(num):
|
||||
num = float('{:.3g}'.format(num))
|
||||
magnitude = 0
|
||||
while abs(num) >= 1000:
|
||||
magnitude += 1
|
||||
num /= 1000.0
|
||||
return '{}{}'.format('{:f}'.format(num).rstrip('0').rstrip('.'), ['', 'K', 'M', 'B', 'T'][magnitude])
|
||||
|
||||
|
||||
def updateMovies(api_key, logf):
|
||||
|
||||
try:
|
||||
@ -642,7 +642,7 @@ def updateCrypto(api_key, logf):
|
||||
|
||||
if symbol.upper() + ',' + base.upper() == sb:
|
||||
|
||||
coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['price_over_24hr'], 'percent_change': d['percent_over_24hr'], 'volume': d['volume'], 'day_low': d['day_low'], 'day_high': d['day_high']}
|
||||
coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['price_over_24hr'], 'percent_change': d['percent_over_24hr'], 'volume': human_format(d['volume']), 'day_low': d['day_low'], 'day_high': d['day_high']}
|
||||
|
||||
all_crypto_settings['symbols'] = coin_info
|
||||
with open('csv/crypto_settings.json', 'w+') as f:
|
||||
|
Loading…
Reference in New Issue
Block a user