diff --git a/stockTicker.py b/stockTicker.py index d30bfc3..b164c0e 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -74,7 +74,7 @@ class StockTicker(): 'Economic Calendar': self.getEconomicImage, 'IPO Calendar':self.getIpoImage, 'IPO Calendar Prof':self.getIpoProfessional, 'Economic Calendar Prof': self.getEconomicProfessional, 'Gainers, Losers, Active Prof': self.getMarketProfessional, 'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional, 'Jokes Prof': self.getJokesProfessional, - 'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional, + 'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional, 'Sector Performance Prof': self.getSectorProfessional, 'Daily Forecast Prof':self.getDailyWeatherProfessional, 'Sports (Team Stats) Prof':lambda : self.getLeagueTableProfessional('NHL'), 'Sports (Upcoming Games) Prof': lambda : self.getLeagueProfessional('NHL', 'future'), 'Sports (Past Games) Prof': lambda : self.getLeagueProfessional('NBA', 'past'), 'Custom Messages Prof': self.getUserMessagesProfessional, 'Custom Images Prof': self.getUserImagesProfessional, 'Movies Prof': self.getMoviesProfessional, 'Sports (Live Games) Prof': lambda : self.getLeagueProfessional('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', 'Sector Performance':'csv/sector_settings.json'} + 'Gainers, Losers, Active':'csv/market_settings.json', 'Gainers, Losers, Active Prof':'csv/market_settings.json', 'Sector Performance':'csv/sector_settings.json', 'Sector Performance Prof':'csv/sector_settings.json'} def openImage(self, image_file): @@ -966,6 +966,21 @@ class StockTicker(): newWidth = max(w2 + text_width_change, text_width_current) +15 img = img.crop((0,0,newWidth,32)) + elif 'Sector' in CHANGE: + 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 +100 , 32)) + d = ImageDraw.Draw(img) + + d.text((4, 0), TICKER, fill=(255, 255, 255), font=font) + d.text((4, 8), CURRENT, fill=self.greenORred, font=font) + + img.paste(ARROW, ((w2 + 7),10)) + newWidth = max(w2 + ARROW.size[0] + 7, text_width_current) +15 + img = img.crop((0,0,newWidth,32)) + else: text_width_current, text_height = self.get_text_dimensions(CURRENT, font) @@ -6978,6 +6993,55 @@ class StockTicker(): finalDisplayImage = self.stitchImage(image_list) return finalDisplayImage + + + def getSectorProfessional(self): + self.blank = Image.new('RGB', (0, 16)) + + f = open('csv/sector_settings.json', 'r') + sector_settings = json.load(f) + f.close() + + if sector_settings['title']: + title_img = self.openImage('feature_titles/small_feature_titles/sector.png') + image_list = [title_img, Image.new('RGB', (5, 16))] + 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, professional=True) + change = 'Sector' + current = '%.2f' % abs(float(info['current'])) + '%' #TEXT + midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT + if sector_settings['logos']: + try: + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'sector') + logo = Image.open(os.path.join(logos_path, category + '.png')) + # half the size of the logo + width, height = logo.size + logo = logo.resize((int(width/2), int(height/2))) + stitchedStock = self.stitchImage([logo,midFrame]) + except Exception as e: + stitchedStock = midFrame + else: + stitchedStock = midFrame + image_list.append(stitchedStock) + image_list.append(self.blank) + + except Exception as e: + pass + + finalDisplayImage = self.stitchImage(image_list) + self.blank = Image.new('RGB', (10, 32)) + return finalDisplayImage def ip_viewer(self): @@ -7026,6 +7090,7 @@ class StockTicker(): economic = self.getEconomicProfessional() jokes = self.getJokesProfessional() market = self.getMarketProfessional() + sector = self.getSectorProfessional() x_offset = 0 news.paste(weather, (x_offset, 16)) @@ -7064,6 +7129,8 @@ class StockTicker(): x_offset += jokes.size[0] news.paste(market, (x_offset, 16)) x_offset += market.size[0] + news.paste(sector, (x_offset, 16)) + x_offset += sector.size[0] self.double_buffer = self.matrix.CreateFrameCanvas() while True: kill = stock_ticker.scrollImage(news, offset_x = 128)