fixed decimal point issues
This commit is contained in:
parent
52aef39e6f
commit
8753fdd454
@ -71,7 +71,7 @@ def updateStocks(api_key):
|
|||||||
stock_info = {}
|
stock_info = {}
|
||||||
|
|
||||||
for stock in data:
|
for stock in data:
|
||||||
stock_info[stock['symbol']] = {'current': stock['price'], 'opening': float(stock['price']) - float(stock['change_since'])}
|
stock_info[stock['symbol']] = {'current': stock['price'], 'change': stock['change_since'], 'percent_change':stock['percent']}
|
||||||
|
|
||||||
print(stock_info)
|
print(stock_info)
|
||||||
all_stocks_settings['symbols'] = stock_info
|
all_stocks_settings['symbols'] = stock_info
|
||||||
@ -127,7 +127,7 @@ def updateCrypto(api_key):
|
|||||||
symbol = d['symbol']
|
symbol = d['symbol']
|
||||||
base = d['currency']
|
base = d['currency']
|
||||||
|
|
||||||
coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['percent_over_24hr']}
|
coin_info[symbol.upper() + ',' + base.upper()] = {'current': d['price'], '24hr_change': d['price_over_24hr'], 'percent_change': d['percent_over_24hr']}
|
||||||
|
|
||||||
all_crypto_settings['symbols'] = coin_info
|
all_crypto_settings['symbols'] = coin_info
|
||||||
|
|
||||||
@ -175,12 +175,12 @@ def updateForex(api_key):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print(data)
|
||||||
c_dict = {}
|
c_dict = {}
|
||||||
|
|
||||||
for d in data:
|
for d in data:
|
||||||
|
|
||||||
c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr']}
|
c_dict[d['uid'].replace('/',',')] = {'current': d['rate'], '24hr_change': d['rate_over_24hr'], 'percent_change':d['percent_over_24hr']}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -572,6 +572,7 @@ if __name__ == '__main__':
|
|||||||
api_keys = f.readlines()
|
api_keys = f.readlines()
|
||||||
api_key = api_keys[0].strip()
|
api_key = api_keys[0].strip()
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
weather_key = api_keys[1].strip()
|
weather_key = api_keys[1].strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
File diff suppressed because one or more lines are too long
@ -929,15 +929,17 @@ class StockTicker():
|
|||||||
try:
|
try:
|
||||||
ticker, base = cb.split(',')
|
ticker, base = cb.split(',')
|
||||||
current = float(coin_info[cb]["current"])
|
current = float(coin_info[cb]["current"])
|
||||||
change = float(coin_info[cb]["24hr_change"])
|
point_change = float(coin_info[cb]["24hr_change"])
|
||||||
|
|
||||||
percent_change = '%.2f' % abs(change) +'%'
|
percent_change = float(coin_info[cb]["percent_change"])
|
||||||
|
|
||||||
|
|
||||||
point_change = '%.2f' % abs(change/100 * current)
|
|
||||||
|
|
||||||
arrow, change = self.getArrow(change)
|
arrow, change = self.getArrow(point_change)
|
||||||
current = '%.2f' % current
|
|
||||||
|
percent_change = str(abs(percent_change))
|
||||||
|
point_change = str(abs(point_change))
|
||||||
|
|
||||||
if not all_crypto_settings['percent']:
|
if not all_crypto_settings['percent']:
|
||||||
percent_change = False
|
percent_change = False
|
||||||
if not all_crypto_settings['point']:
|
if not all_crypto_settings['point']:
|
||||||
@ -1006,13 +1008,12 @@ class StockTicker():
|
|||||||
change = float(coin_info[cb]["24hr_change"])
|
change = float(coin_info[cb]["24hr_change"])
|
||||||
arrow, change = self.getArrow(change, professional=True)
|
arrow, change = self.getArrow(change, professional=True)
|
||||||
|
|
||||||
if all_crypto_settings["point"]:
|
if all_crypto_settings["percent"]:
|
||||||
# convert percent to points
|
# convert percent to points
|
||||||
change = abs(change)/100 * current
|
change = str(abs(float(coin_info[cb]['percent_change']))) + '%'
|
||||||
change = str(change)
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
change = str(change)
|
change = str(abs(float(change)))
|
||||||
|
|
||||||
current = str(current)
|
current = str(current)
|
||||||
midFrame = self.textToImageProf(ticker + '(' + base + ')', current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
|
midFrame = self.textToImageProf(ticker + '(' + base + ')', current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
|
||||||
@ -1071,10 +1072,10 @@ class StockTicker():
|
|||||||
current = float(forex_settings[sb]['current'])
|
current = float(forex_settings[sb]['current'])
|
||||||
change = float(forex_settings[sb]['24hr_change'])
|
change = float(forex_settings[sb]['24hr_change'])
|
||||||
|
|
||||||
percent_change = str(abs(change)) +'%'
|
percent_change = str(abs(forex_settings[sb]['percent_change'])) +'%'
|
||||||
|
|
||||||
|
|
||||||
point_change = str(abs(change/100 * current))
|
point_change = str(abs(change))
|
||||||
|
|
||||||
if not all_forex_settings['percent']:
|
if not all_forex_settings['percent']:
|
||||||
percent_change = False
|
percent_change = False
|
||||||
@ -1162,7 +1163,7 @@ class StockTicker():
|
|||||||
|
|
||||||
if all_forex_settings["percent"]:
|
if all_forex_settings["percent"]:
|
||||||
# convert percent to points
|
# convert percent to points
|
||||||
change = abs(change)/current * 100
|
change = abs(forex_settings[sb]['percent_change'])/current * 100
|
||||||
|
|
||||||
change = str(change) + '%'
|
change = str(change) + '%'
|
||||||
else:
|
else:
|
||||||
@ -1234,13 +1235,15 @@ class StockTicker():
|
|||||||
try:
|
try:
|
||||||
info = stock_info[symbol]
|
info = stock_info[symbol]
|
||||||
|
|
||||||
change = float(info['current'])-float(info['opening']) #TEXT
|
change = float(info['change']) #TEXT
|
||||||
ticker = symbol #TEXT
|
ticker = symbol #TEXT
|
||||||
|
|
||||||
percent_change = str(abs(float(change)/float(info['current'])*100)) + '%'
|
|
||||||
point_change = str(abs(change))
|
|
||||||
arrow, change = self.getArrow(change)
|
arrow, change = self.getArrow(change)
|
||||||
|
|
||||||
|
percent_change = str(abs(float(info['percent_change']))) + '%'
|
||||||
|
point_change = str(abs(change))
|
||||||
|
|
||||||
print(percent_change, point_change)
|
print(percent_change, point_change)
|
||||||
|
|
||||||
current = str(float(info['current'])) #TEXT
|
current = str(float(info['current'])) #TEXT
|
||||||
@ -1313,7 +1316,7 @@ class StockTicker():
|
|||||||
try:
|
try:
|
||||||
info = stock_info[symbol]
|
info = stock_info[symbol]
|
||||||
|
|
||||||
change = float(info['current'])-float(info['opening']) #TEXT
|
change = float(info['change'])#TEXT
|
||||||
ticker = symbol #TEXT
|
ticker = symbol #TEXT
|
||||||
|
|
||||||
|
|
||||||
@ -1321,12 +1324,9 @@ class StockTicker():
|
|||||||
arrow, change = self.getArrow(change, professional=True)
|
arrow, change = self.getArrow(change, professional=True)
|
||||||
|
|
||||||
if all_stocks_settings["percent"]:
|
if all_stocks_settings["percent"]:
|
||||||
# convert percent to points
|
change = str(abs(float(info['percent_change']))) + '%'
|
||||||
change = change/float(info['current'])* 100
|
|
||||||
|
|
||||||
change = str(change) + '%'
|
|
||||||
else:
|
|
||||||
change = str(change)
|
|
||||||
current = str(float(info['current'])) #TEXT
|
current = str(float(info['current'])) #TEXT
|
||||||
midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
|
midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user