diff --git a/stockTicker.py b/stockTicker.py index c9b4fd7..023141f 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -71,7 +71,7 @@ class StockTicker(): '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'), 'News':self.getNewsImage, 'Custom Messages': self.getUserMessages, 'Commodities': self.getCommoditiesImage, 'Indices': self.getIndicesImage, 'Movies': self.getMoviesImage, 'Gainers, Losers, Active': self.getMarketImage, - 'Economic Calendar': self.getEconomicImage, 'IPO Calendar':self.getIpoImage, 'IPO Calendar Prof':self.getIpoProfessional, 'Economic Calendar Prof': self.getEconomicProfessional, + '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, @@ -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':'csv/market_settings.json', 'Gainers, Losers, Active Prof':'csv/market_settings.json'} def openImage(self, image_file): @@ -6678,6 +6678,265 @@ class StockTicker(): finalDisplayImage = self.stitchImage(image_list) return finalDisplayImage + + def getMarketProfessional(self): + self.blank = Image.new('RGB', (0, 16)) + + f = open('csv/market_settings.json', 'r') + market_settings = json.load(f) + f.close() + + if market_settings['title']: + title_img = self.openImage('feature_titles/small_feature_titles/market.png') + image_list = [title_img, Image.new('RGB', (5, 16))] + image_list.append(self.blank) + else: + image_list = [] + + active_info = market_settings['mostactive'] + active_symbols = list(active_info.keys()) + gainers_info = market_settings['gainers'] + gainers_symbols = list(gainers_info.keys()) + losers_info = market_settings['losers'] + losers_symbols = list(losers_info.keys()) + + for category in market_settings['categories']: + if category == 'Most Active': + most_active = self.openImage('logos/active_prof.png') + image_list.append(most_active) + for i, symbol in enumerate(active_symbols): + try: + info = active_info[symbol] + change = float(info['change'])#TEXT + ticker = symbol #TEXT + + arrow, change = self.getArrow(change, professional=True) + + if market_settings["percent"]: + change = '%.2f' % abs(float(info['percent_change'])) + '%' + else: + change = '%.2f' % abs(change) + + current = '%.2f' % float(info['current']) #TEXT + midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT + + if market_settings['logos']: + try: + try: #load the tiny logo + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'tiny_stocks') + + logo = Image.open(os.path.join(logos_path, ticker + '.png')) + + except: # load the big logo and scale it + + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks') + + logo = Image.open(os.path.join(logos_path, ticker + '.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 + try: + if market_settings['lohivol']: + font = ImageFont.load("./fonts/4x6.pil") + try: + day_low = '%.2f' % float(info['day_low']) + day_high = '%.2f' % float(info['day_high']) + volume = info['volume'] + + daylow_img = self.textImage(day_low, font, r=0, g=255, b=0) + daylow_t_img = self.textImage('Lo', font, r=255, g=255, b=255) + dayhi_img = self.textImage(day_high, font, r=0,g=255,b=0) + dayhi_t_img = self.textImage('Hi', font, r=255,g=255,b=255) + vol_img = self.textImage(volume, font, r=0,g=255,b=0) + vol_t_img = self.textImage('Vol', font, r=255,g=255,b=255) + lohivol_img = Image.new('RGB', (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0] + vol_img.size[0] + 8, 16)) + lohivol_img.paste(daylow_t_img, (0, 3)) + lohivol_img.paste(daylow_img, (daylow_t_img.size[0],3)) + lohivol_img.paste(dayhi_t_img, (0, 9)) + lohivol_img.paste(dayhi_img, (dayhi_t_img.size[0], 9)) + lohivol_img.paste(vol_t_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0])+2, 3)) + lohivol_img.paste(vol_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0], 3)) + except: + pass + except: + pass + image_list.append(stitchedStock) + try: + if all_stocks_settings['lohivol']: + try: + image_list.append(lohivol_img) + except: + pass + except: + pass + image_list.append(self.blank) + + except Exception as e: + pass + + elif category == 'Top Losers': + top_losers = self.openImage('logos/losers_prof.png') + image_list.append(top_losers) + for i, symbol in enumerate(losers_symbols): + try: + info = losers_info[symbol] + change = float(info['change'])#TEXT + ticker = symbol #TEXT + + arrow, change = self.getArrow(change, professional=True) + + if market_settings["percent"]: + change = '%.2f' % abs(float(info['percent_change'])) + '%' + else: + change = '%.2f' % abs(change) + + current = '%.2f' % float(info['current']) #TEXT + midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT + + if market_settings['logos']: + try: + try: #load the tiny logo + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'tiny_stocks') + + logo = Image.open(os.path.join(logos_path, ticker + '.png')) + + except: # load the big logo and scale it + + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks') + + logo = Image.open(os.path.join(logos_path, ticker + '.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 + try: + if market_settings['lohivol']: + font = ImageFont.load("./fonts/4x6.pil") + try: + day_low = '%.2f' % float(info['day_low']) + day_high = '%.2f' % float(info['day_high']) + volume = info['volume'] + + daylow_img = self.textImage(day_low, font, r=0, g=255, b=0) + daylow_t_img = self.textImage('Lo', font, r=255, g=255, b=255) + dayhi_img = self.textImage(day_high, font, r=0,g=255,b=0) + dayhi_t_img = self.textImage('Hi', font, r=255,g=255,b=255) + vol_img = self.textImage(volume, font, r=0,g=255,b=0) + vol_t_img = self.textImage('Vol', font, r=255,g=255,b=255) + lohivol_img = Image.new('RGB', (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0] + vol_img.size[0] + 8, 16)) + lohivol_img.paste(daylow_t_img, (0, 3)) + lohivol_img.paste(daylow_img, (daylow_t_img.size[0],3)) + lohivol_img.paste(dayhi_t_img, (0, 9)) + lohivol_img.paste(dayhi_img, (dayhi_t_img.size[0], 9)) + lohivol_img.paste(vol_t_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0])+2, 3)) + lohivol_img.paste(vol_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0], 3)) + except: + pass + except: + pass + image_list.append(stitchedStock) + try: + if all_stocks_settings['lohivol']: + try: + image_list.append(lohivol_img) + except: + pass + except: + pass + image_list.append(self.blank) + except Exception as e: + pass + + elif category == 'Top Gainers': + top_gainers = self.openImage('logos/gainers_prof.png') + image_list.append(top_gainers) + for i, symbol in enumerate(gainers_symbols): + try: + info = gainers_info[symbol] + change = float(info['change'])#TEXT + ticker = symbol #TEXT + arrow, change = self.getArrow(change, professional=True) + if market_settings["percent"]: + change = '%.2f' % abs(float(info['percent_change'])) + '%' + else: + change = '%.2f' % abs(change) + current = '%.2f' % float(info['current']) #TEXT + midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT + + if market_settings['logos']: + try: + try: #load the tiny logo + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'tiny_stocks') + + logo = Image.open(os.path.join(logos_path, ticker + '.png')) + + except: # load the big logo and scale it + + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'stocks') + + logo = Image.open(os.path.join(logos_path, ticker + '.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 + try: + if market_settings['lohivol']: + font = ImageFont.load("./fonts/4x6.pil") + try: + day_low = '%.2f' % float(info['day_low']) + day_high = '%.2f' % float(info['day_high']) + volume = info['volume'] + + daylow_img = self.textImage(day_low, font, r=0, g=255, b=0) + daylow_t_img = self.textImage('Lo', font, r=255, g=255, b=255) + dayhi_img = self.textImage(day_high, font, r=0,g=255,b=0) + dayhi_t_img = self.textImage('Hi', font, r=255,g=255,b=255) + vol_img = self.textImage(volume, font, r=0,g=255,b=0) + vol_t_img = self.textImage('Vol', font, r=255,g=255,b=255) + lohivol_img = Image.new('RGB', (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0] + vol_img.size[0] + 8, 16)) + lohivol_img.paste(daylow_t_img, (0, 3)) + lohivol_img.paste(daylow_img, (daylow_t_img.size[0],3)) + lohivol_img.paste(dayhi_t_img, (0, 9)) + lohivol_img.paste(dayhi_img, (dayhi_t_img.size[0], 9)) + lohivol_img.paste(vol_t_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0])+2, 3)) + lohivol_img.paste(vol_img, (max(daylow_t_img.size[0] + daylow_img.size[0], dayhi_t_img.size[0] + dayhi_img.size[0]) + 2+vol_t_img.size[0], 3)) + except: + pass + except: + pass + image_list.append(stitchedStock) + try: + if all_stocks_settings['lohivol']: + try: + image_list.append(lohivol_img) + except: + pass + except: + pass + 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): @@ -6722,6 +6981,9 @@ class StockTicker(): messages = self.getUserMessagesProfessional() images = self.getUserImagesProfessional() ipo = self.getIpoProfessional() + economic = self.getEconomicProfessional() + jokes = self.getJokesProfessional() + market = self.getMarketProfessional() x_offset = 0 news.paste(weather, (x_offset, 16)) @@ -6758,6 +7020,8 @@ class StockTicker(): x_offset += economic.size[0] news.paste(jokes, (x_offset, 16)) x_offset += jokes.size[0] + news.paste(market, (x_offset, 16)) + x_offset += market.size[0] self.double_buffer = self.matrix.CreateFrameCanvas() while True: kill = stock_ticker.scrollImage(news, offset_x = 128)