Merge pull request #5 from fin-tic/dev

Dev
This commit is contained in:
Neythen Treloar 2022-02-22 20:47:22 +00:00 committed by GitHub
commit 45bfb41f14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 36 deletions

View File

@ -71,7 +71,7 @@ def updateStocks(api_key):
stock_info = {}
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)
all_stocks_settings['symbols'] = stock_info
@ -127,7 +127,7 @@ def updateCrypto(api_key):
symbol = d['symbol']
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
@ -175,12 +175,12 @@ def updateForex(api_key):
print(data)
c_dict = {}
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_key = api_keys[0].strip()
try:
weather_key = api_keys[1].strip()
except Exception as e:

File diff suppressed because one or more lines are too long

View File

@ -260,11 +260,14 @@ class StockTicker():
if stocks:
update_process.join()
update_process.terminate()
if current_img == 1:
current_img = 2
elif current_img == 2:
current_img = 1
offset_x = 0
update_process.join()
update_process.terminate()
def scrollImageStacked(self, image, offset_x = 0, offset_y = 0):
img_width, img_height = image.size
@ -427,6 +430,7 @@ class StockTicker():
if not repeat:
break
update_process.join()
update_process.terminate()
i+=1
def scrollProfessionalAnimated(self, options, animation = 'on'):
@ -510,6 +514,7 @@ class StockTicker():
offset_x1 = 0
update_process.join()
update_process.terminate()
update_process = Process(target = self.updateMultiple, args = ([top[(i1+1) % len(top)]+ ' Prof'],))
update_process.start()
image1 = self.openImage('./display_images/' + top[i1 % len(top)] +' Prof.ppm')
@ -531,6 +536,7 @@ class StockTicker():
update_process.join()
update_process.terminate()
update_process = Process(target = self.updateMultiple, args = ([bottom[i2 % len(bottom)]+ ' Prof'],))
update_process.start()
image2 = self.openImage('./display_images/' + bottom[(i2+1) % len(bottom)] +' Prof.ppm')
@ -581,6 +587,8 @@ class StockTicker():
if kill: break
def scrollMultiple(self, animation = 'down'):
# scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed
@ -929,15 +937,18 @@ class StockTicker():
try:
ticker, base = cb.split(',')
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)
current = '%.2f' % current
arrow, change = self.getArrow(point_change)
percent_change = str(abs(percent_change))
point_change = str(abs(point_change))
current = str(current)
if not all_crypto_settings['percent']:
percent_change = False
if not all_crypto_settings['point']:
@ -951,7 +962,7 @@ class StockTicker():
logo = self.openImage(os.path.join(logos_path, ticker + '.png'))
stitchedStock = self.stitchImage([logo,midFrame])
except:
except Exception as e:
stitchedStock = midFrame
else:
@ -962,6 +973,7 @@ class StockTicker():
image_list.append(self.blank)
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]
self.logf.write(str(e))
@ -1006,13 +1018,12 @@ class StockTicker():
change = float(coin_info[cb]["24hr_change"])
arrow, change = self.getArrow(change, professional=True)
if all_crypto_settings["point"]:
if all_crypto_settings["percent"]:
# convert percent to points
change = abs(change)/100 * current
change = str(change)
change = str(abs(float(coin_info[cb]['percent_change']))) + '%'
else:
change = str(change)
change = str(abs(float(change)))
current = str(current)
midFrame = self.textToImageProf(ticker + '(' + base + ')', current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
@ -1071,10 +1082,10 @@ class StockTicker():
current = float(forex_settings[sb]['current'])
change = float(forex_settings[sb]['24hr_change'])
percent_change = str(abs(change)) +'%'
percent_change = str(abs(float(forex_settings[sb]['percent_change']))) +'%'
point_change = str(abs(change/100 * current))
point_change = str(abs(change))
if not all_forex_settings['percent']:
percent_change = False
@ -1085,7 +1096,7 @@ class StockTicker():
current = '%.3f' % current
current = str(current)
midFrame = self.textToImage(base+ '(' + symbol + ')', current, arrow, percent_change, point_change) #IMAGE THE TEXT
@ -1114,6 +1125,7 @@ class StockTicker():
image_list.append(self.blank)
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]
self.logf.write(str(e))
@ -1162,7 +1174,7 @@ class StockTicker():
if all_forex_settings["percent"]:
# convert percent to points
change = abs(change)/current * 100
change = abs(float(forex_settings[sb]['percent_change']))
change = str(change) + '%'
else:
@ -1234,13 +1246,15 @@ class StockTicker():
try:
info = stock_info[symbol]
change = float(info['current'])-float(info['opening']) #TEXT
change = float(info['change']) #TEXT
ticker = symbol #TEXT
percent_change = str(abs(float(change)/float(info['current'])*100)) + '%'
point_change = str(abs(change))
arrow, change = self.getArrow(change)
percent_change = str(abs(float(info['percent_change']))) + '%'
point_change = str(abs(change))
print(percent_change, point_change)
current = str(float(info['current'])) #TEXT
@ -1313,7 +1327,7 @@ class StockTicker():
try:
info = stock_info[symbol]
change = float(info['current'])-float(info['opening']) #TEXT
change = float(info['change'])#TEXT
ticker = symbol #TEXT
@ -1321,12 +1335,11 @@ class StockTicker():
arrow, change = self.getArrow(change, professional=True)
if all_stocks_settings["percent"]:
# convert percent to points
change = change/float(info['current'])* 100
change = str(change) + '%'
change = str(abs(float(info['percent_change']))) + '%'
else:
change = str(change)
change = str(abs(change))
current = str(float(info['current'])) #TEXT
midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT
@ -1781,7 +1794,7 @@ class StockTicker():
img = img.crop((0,0,x_offset ,32))
imgs.append(img)
except Exception as e:
raise e
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
self.logf.write(str(e))