diff --git a/stockTicker.py b/stockTicker.py index 91c2144..9ca9a23 100755 --- a/stockTicker.py +++ b/stockTicker.py @@ -68,19 +68,19 @@ class StockTicker(): 'Daily Forecast':self.getDailyWeatherImage, 'Current Weather': self.getTodayWeatherImage, '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, + 'News':self.getNewsImage, 'Custom Messages': self.getUserMessages, 'Commodities': self.getCommoditiesImage, 'Indices': self.getIndicesImage, 'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional, - 'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional} + 'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional} self.JSONs = {'Stocks': 'csv/stocks_settings.json', 'Crypto': 'csv/crypto_settings.json', 'Forex': 'csv/forex_settings.json', - 'Daily Forecast':'csv/daily_weather.json', 'Current Weather': 'csv/current_weather.json', 'Commodities':'csv/commodities_settings.json', + 'Daily Forecast':'csv/daily_weather.json', 'Current Weather': 'csv/current_weather.json', 'Commodities':'csv/commodities_settings.json', 'Indices': 'csv/indices_settings.json', 'Sports (Team Stats)': 'csv/league_tables.json', 'Sports (Past Games)': 'csv/past_games.json', 'Sports (Upcoming Games)': 'csv/upcoming_games.json', 'Sports (Live Games)': 'csv/live_games.json', 'News':'csv/news_settings.json', 'Custom Images': 'csv/image_settings.json', 'Custom GIFs': 'csv/GIF_settings.json', 'Custom Messages': 'csv/message_settings.json', 'Stocks Prof': 'csv/stocks_settings.json', 'Crypto Prof': 'csv/crypto_settings.json', 'Forex Prof': 'csv/forex_settings.json', - 'Current Weather Prof': 'csv/current_weather.json', 'News Prof':'csv/news_settings.json', 'Commodities Prof':'csv/commodities_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'} def openImage(self, image_file): @@ -1065,6 +1065,160 @@ class StockTicker(): self.blank = Image.new('RGB', (10, 32)) return finalDisplayImage + + def getIndicesImage(self): + + f = open('csv/indices_settings.json', 'r') + all_indices_settings = json.load(f) + f.close() + + if all_indices_settings['title']: + title_img = self.openImage('feature_titles/indices.png') + image_list = [title_img] + image_list.append(self.blank) + else: + image_list = [] + + index_info = all_indices_settings['symbols'] + symbols = list(index_info.keys()) + + + for i, symbol in enumerate(symbols): + + try: + info = index_info[symbol] + + change = float(info['point_change']) #TEXT + symb = symbol + ticker = info['name'] #TEXT + arrow, change = self.getArrow(change) + point_change = '%.2f' % abs(change) + percent_change = '%.2f' % abs(float(info['percent_change'])) + '%' + + # point_change2 = abs(change) + # point_changefinal = '{0:.10f}'.format(point_change2).rstrip("0") + # point_change = str(point_changefinal) + + + current = '%.2f' % float(info['current']) + # current_final = '{0:.10f}'.format(current).rstrip("0") + # current = str(current_final) + + + + if not all_indices_settings['percent']: + percent_change = False + if not all_indices_settings['point']: + point_change = False + + + + + midFrame = self.textToImage(ticker, current, arrow, percent_change, point_change) #IMAGE THE TEXT + + if all_indices_settings['logos']: + try: + logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'indices') + + logo = self.openImage(os.path.join(logos_path, symb + '.png')) + stitchedIndex = self.stitchImage([logo,midFrame]) + except Exception as e: + + stitchedIndex = midFrame + else: + stitchedIndex = midFrame + + image_list.append(stitchedIndex) + + + image_list.append(self.blank) + except Exception as e: + pass + + + + finalDisplayImage = self.stitchImage(image_list) + + + + return finalDisplayImage + + + def getIndicesProfessional(self): + self.blank = Image.new('RGB', (0, 16)) + + f = open('csv/indices_settings.json', 'r') + all_indices_settings = json.load(f) + f.close() + + if all_indices_settings['title']: + title_img = self.openImage('feature_titles/small_feature_titles/indices.png') + image_list = [title_img, Image.new('RGB', (5, 16))] + image_list.append(self.blank) + else: + image_list = [] + + index_info = all_indices_settings['symbols'] + symbols = list(index_info.keys()) + + for i, symbol in enumerate(symbols): + + try: + info = index_info[symbol] + + change = float(info['point_change']) #TEXT + symb = symbol + ticker = info['name'] #TEXT + arrow, change = self.getArrow(change, professional=True) + if all_indices_settings["percent"]: + change = '%.2f' % abs(float(info['percent_change'])) + '%' + else: + change = '%.2f' % abs(change) + current = '%.2f' % float(info['current']) + + + midFrame = self.textToImageProf(ticker, current, change, arrow, font=ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT + + if all_indices_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_indices') + + 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'), 'indices') + + logo = Image.open(os.path.join(logos_path, symb + '.png')) + # half the size of the logo + width, height = logo.size + + logo = logo.resize((int(width/2), int(height/2))) + stitchedIndex = self.stitchImage([logo,midFrame]) + except Exception as e: + + stitchedIndex = midFrame + else: + stitchedIndex = midFrame + + image_list.append(stitchedIndex) + + + 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 getCommoditiesImage(self): f = open('csv/commodities_settings.json', 'r') @@ -2874,6 +3028,7 @@ class StockTicker(): stock = self.getStockProfessional() weather = self.getTodayWeatherProfessional() commodities = self.getCommoditiesProfessional() + indices = self.getIndicesProfessional() x_offset = 0 news.paste(weather, (x_offset, 16)) @@ -2886,6 +3041,8 @@ class StockTicker(): x_offset += forex.size[0] news.paste(commodities, (x_offset, 16)) x_offset += commodities.size[0] + news.paste(indices, (x_offset, 16)) + x_offset += indices.size[0] self.double_buffer = self.matrix.CreateFrameCanvas() while True: kill = stock_ticker.scrollImage(news, offset_x = 128) @@ -2960,6 +3117,9 @@ class StockTicker(): elif msg == 'CO': #commodities self.scrollFunctionsAnimated(['commodities', 'commodities'],animation = 'traditional') + elif msg == 'WI': #indices + self.scrollFunctionsAnimated(['indices', 'indices'],animation = 'traditional') + elif msg == 'A': #everything #userSettings = ['display_gif', 'text', 'display_image', 'stocks', 'crypto', 'forex', 'today_weather', 'daily_weather', 'league_table', 'league_games', 'news'] # these wil be read from csv, just for demo