From 9a357655f4e5f0795e093e1d34c63d2722268c5e Mon Sep 17 00:00:00 2001 From: Justin Date: Wed, 13 Sep 2023 22:21:50 +0800 Subject: [PATCH] added display name --- stockTicker.py | 52 +++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/stockTicker.py b/stockTicker.py index bd11fc1..d47ac7e 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -1119,9 +1119,7 @@ class StockTicker(): point_changefinal = '{0:.10f}'.format(point_change2).rstrip("0") current_final = '{0:.10f}'.format(current).rstrip("0") percent_change = float(coin_info[cb]["percent_change"]) - - - + arrow, change = self.getArrow(point_change) percent_change = '%.2f' % abs(percent_change) + '%' @@ -1141,13 +1139,17 @@ class StockTicker(): percent_change = False if not all_crypto_settings['point']: point_change = False - - midFrame = self.textToImage(ticker + '(' + base + ')', current, arrow, percent_change, point_change) #IMAGE THE TEXT + + if names: + ticker = coin_info[cb]['name'] + midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT + else: + midFrame = self.textToImage(ticker + '(' + base + ')', current, arrow, percent_change, point_change) #IMAGE THE TEXT if all_crypto_settings['logos']: try: + ticker, base = cb.split(',') logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'crypto') - logo = self.openImage(os.path.join(logos_path, ticker + '.png')) stitchedStock = self.stitchImage([logo,midFrame]) except Exception as e: @@ -2072,14 +2074,12 @@ class StockTicker(): f = open('csv/stocks_settings.json', 'r') all_stocks_settings = json.load(f) f.close() - if all_stocks_settings['title']: title_img = self.openImage('feature_titles/stocks.png') image_list = [title_img] image_list.append(self.blank) else: image_list = [] - if all_stocks_settings['chart']: try: f = open('csv/portfolio_settings.json', 'r') @@ -2087,7 +2087,6 @@ class StockTicker(): f.close() except: pass - try: if all_stocks_settings['prepost']: try: @@ -2098,7 +2097,6 @@ class StockTicker(): pass except: pass - try: if all_stocks_settings['display_name']: names = True @@ -2108,19 +2106,20 @@ class StockTicker(): names = False pass - stock_info = all_stocks_settings['symbols'] symbols = list(stock_info.keys()) timenow = datetime.now(ny_zone).replace(tzinfo=None).strftime("%H:%M:%S") weekday = datetime.now(ny_zone).replace(tzinfo=None).weekday() for i, symbol in enumerate(symbols): - try: info = stock_info[symbol] change = float(info['change']) #TEXT - ticker = symbol #TEXT + if names: + ticker = info['name'] #TEXT + else: + ticker = symbol arrow, change = self.getArrow(change) @@ -2133,17 +2132,16 @@ class StockTicker(): percent_change = False if not all_stocks_settings['point']: point_change = False - + midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT - + if all_stocks_settings['logos']: try: + ticker = symbol logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks') - logo = self.openImage(os.path.join(logos_path, ticker + '.png')) stitchedStock = self.stitchImage([logo,midFrame]) except Exception as e: - stitchedStock = midFrame else: stitchedStock = midFrame @@ -2174,7 +2172,6 @@ class StockTicker(): pass except: pass - try: if all_stocks_settings['prepost']: font = ImageFont.load("./fonts/6x13.pil") @@ -2251,7 +2248,6 @@ class StockTicker(): except: pass - try: if all_stocks_settings['chart'] and (symbol in portfolio_settings): #IF USER INPUTTED PORTFOLIO SETTINGS, DISPLAY PORTFOLIO INFO try: @@ -6753,7 +6749,10 @@ class StockTicker(): try: info = active_info[symbol] change = float(info['change']) #TEXT - ticker = symbol #TEXT + if names: + ticker = info['name'] #TEXT + else: + ticker = symbol arrow, change = self.getArrow(change) percent_change = '%.2f' % abs(float(info['percent_change'])) + '%' point_change = '%.2f' % abs(change) @@ -6765,6 +6764,7 @@ class StockTicker(): midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT if market_settings['logos']: try: + ticker = symbol logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks') logo = self.openImage(os.path.join(logos_path, ticker + '.png')) stitchedStock = self.stitchImage([logo,midFrame]) @@ -6818,7 +6818,10 @@ class StockTicker(): try: info = gainers_info[symbol] change = float(info['change']) #TEXT - ticker = symbol #TEXT + if names: + ticker = info['name'] #TEXT + else: + ticker = symbol arrow, change = self.getArrow(change) percent_change = '%.2f' % abs(float(info['percent_change'])) + '%' point_change = '%.2f' % abs(change) @@ -6830,6 +6833,7 @@ class StockTicker(): midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT if market_settings['logos']: try: + ticker = symbol logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks') logo = self.openImage(os.path.join(logos_path, ticker + '.png')) stitchedStock = self.stitchImage([logo,midFrame]) @@ -6883,7 +6887,10 @@ class StockTicker(): try: info = losers_info[symbol] change = float(info['change']) #TEXT - ticker = symbol #TEXT + if names: + ticker = info['name'] + else: + ticker = symbol #TEXT arrow, change = self.getArrow(change) percent_change = '%.2f' % abs(float(info['percent_change'])) + '%' point_change = '%.2f' % abs(change) @@ -6895,6 +6902,7 @@ class StockTicker(): midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT if market_settings['logos']: try: + ticker = symbol logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks') logo = self.openImage(os.path.join(logos_path, ticker + '.png')) stitchedStock = self.stitchImage([logo,midFrame])