From d4b68ab5177fc16723788ddcff5eca4ce58e823b Mon Sep 17 00:00:00 2001 From: Justin Date: Tue, 15 Aug 2023 15:39:32 +0800 Subject: [PATCH] getsectorimage --- stockTicker.py | 61 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/stockTicker.py b/stockTicker.py index f046dc1..a954915 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -66,7 +66,7 @@ class StockTicker(): #sys.exit() self.points = True # display crypto change in points or percent - self.functions = {'Stocks': self.getStockImage, 'Crypto': self.getCryptoImage, 'Forex': self.getForexImage, + self.functions = {'Stocks': self.getStockImage, 'Crypto': self.getCryptoImage, 'Forex': self.getForexImage, 'Sector Performance': self.getSectorImage, 'Daily Forecast':self.getDailyWeatherImage, 'Current Weather': self.getTodayWeatherImage, 'Jokes': self.getJokesImage, 'Sports (Team Stats)':lambda : self.getLeagueTableImage('premier_league'), 'Sports (Past Games)': lambda:self.getLeagueImage('NBA', 'past'), 'Sports (Upcoming Games)': lambda : self.getLeagueImage('NHL', 'future'), 'Sports (Live Games)': lambda: self.getLeagueImage('NBA', 'live'), @@ -86,7 +86,7 @@ class StockTicker(): 'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json', 'Jokes Prof': 'csv/jokes_settings.json', 'Current Weather Prof': 'csv/current_weather.json', 'News Prof':'csv/news_settings.json', 'Commodities Prof':'csv/commodities_settings.json', 'Indices Prof': 'csv/indices_settings.json', 'Daily Forecast Prof':'csv/daily_weather.json', 'Sports (Team Stats) Prof': 'csv/league_tables.json', 'Sports (Upcoming Games) Prof': 'csv/upcoming_games.json', 'Sports (Past Games) Prof': 'csv/past_games.json', 'Custom Messages Prof': 'csv/message_settings.json', 'Custom Images Prof': 'csv/image_settings.json', 'Movies Prof': 'csv/movie_settings.json', 'Sports (Live Games) Prof': 'csv/live_games.json', 'IPO Calendar Prof': 'csv/ipo_settings.json', 'Economic Calendar Prof': 'csv/economic_settings.json', - 'Gainers, Losers, Active':'csv/market_settings.json', 'Gainers, Losers, Active Prof':'csv/market_settings.json'} + 'Gainers, Losers, Active':'csv/market_settings.json', 'Gainers, Losers, Active Prof':'csv/market_settings.json', 'Sector Performance':'csv/sector_settings.json'} def openImage(self, image_file): @@ -921,7 +921,6 @@ class StockTicker(): w1, text_height = self.get_text_dimensions(TICKER, font) w2, text_height = self.get_text_dimensions(CURRENT, font) - text_width_current = max(w1,w2) img = Image.new('RGB', (text_width_current +1000 , 32)) @@ -934,17 +933,15 @@ class StockTicker(): d.text(((w1+7), 14 - text_height), percent_change, fill=self.greenORred, font=font) w, h = self.get_text_dimensions(percent_change, font) w1 += 7 + w - - - if point_change: img.paste(ARROW, ((w2+ 9),18)) d.text(((w2+29), 16), point_change, fill=self.greenORred, font=font) w,h = self.get_text_dimensions(point_change, font) w2 += 29 + w + if not point_change and not percent_change: + img.paste(ARROW, ((w2+ 9),18)) + w2 += ARROW.size[0] + 9 - - img = img.crop((0,0,max(w1, w2) + 8,32)) return img @@ -6937,6 +6934,51 @@ class StockTicker(): self.blank = Image.new('RGB', (10, 32)) return finalDisplayImage + + def getSectorImage(self): + + f = open('csv/sector_settings.json', 'r') + sector_settings = json.load(f) + f.close() + + if sector_settings['title']: + title_img = self.openImage('feature_titles/sector.png') + image_list = [title_img] + image_list.append(self.blank) + else: + image_list = [] + + data_info = sector_settings['data'] + data_symbols = list(data_info.keys()) + + for category in sector_settings['sectors']: + try: + info = data_info[category] + change = float(info['current']) #TEXT + ticker = category.upper() #TEXT + arrow, change = self.getArrow(change) + current = '%.2f' % abs(float(info['current'])) + '%' #TEXT + percent_change = False + point_change = False + midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT + if sector_settings['logos']: + try: + 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 + + image_list.append(stitchedStock) + image_list.append(self.blank) + except: + pass + + finalDisplayImage = self.stitchImage(image_list) + return finalDisplayImage + def ip_viewer(self): @@ -7113,6 +7155,9 @@ class StockTicker(): elif msg == 'MA': # market self.scrollFunctionsAnimated(['market', 'market'],animation = 'traditional') + + elif msg == 'SE': + self.scrollFunctionsAnimated(['sector', 'sector'],animation = 'traditional') elif msg == 'A': #everything