human_formatize volume
This commit is contained in:
parent
07149aa6df
commit
206fd96dcd
@ -145,7 +145,16 @@ def getCookiesnCrumb():
|
|||||||
with open('crumb.txt', 'w') as f:
|
with open('crumb.txt', 'w') as f:
|
||||||
f.write(crumb)
|
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):
|
def updateStocks(api_key, logf):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -177,7 +186,7 @@ def updateStocks(api_key, logf):
|
|||||||
if len(data) > 0:
|
if len(data) > 0:
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
try:
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
all_stocks_settings['symbols'] = stock_info
|
all_stocks_settings['symbols'] = stock_info
|
||||||
@ -216,7 +225,7 @@ def updateStocks(api_key, logf):
|
|||||||
try:
|
try:
|
||||||
for stock in data['quoteResponse']['result']:
|
for stock in data['quoteResponse']['result']:
|
||||||
if stock['symbol'].replace('BRK-A', 'BRK.A').replace('BRK-B', 'BRK.B') == symbol:
|
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:
|
except:
|
||||||
pass
|
pass
|
||||||
all_stocks_settings['symbols'] = stock_info
|
all_stocks_settings['symbols'] = stock_info
|
||||||
@ -364,15 +373,6 @@ def updateCommodities(api_key, logf):
|
|||||||
#logf.write('. type: ' + str(exc_type))
|
#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])))
|
#logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
|
||||||
#logf.close()
|
#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):
|
def updateMovies(api_key, logf):
|
||||||
@ -642,7 +642,7 @@ def updateCrypto(api_key, logf):
|
|||||||
|
|
||||||
if symbol.upper() + ',' + base.upper() == sb:
|
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
|
all_crypto_settings['symbols'] = coin_info
|
||||||
with open('csv/crypto_settings.json', 'w+') as f:
|
with open('csv/crypto_settings.json', 'w+') as f:
|
||||||
|
Loading…
Reference in New Issue
Block a user