diff --git a/api_caller.py b/api_caller.py index aeede51..3b4a0a6 100644 --- a/api_caller.py +++ b/api_caller.py @@ -250,15 +250,18 @@ def updateCrypto(): def updateNews(): - + max_per_cat = 10 try: try: #load user settings - + headlines = [] settings = json.load(open('csv/news_settings.json', 'r')) - print(settings) - headlines = newsapi.get_top_headlines(**settings) + for setting in settings: + h = newsapi.get_top_headlines(**setting) + if len(h) > max_per_cat: + h = h[0:max_per_cat] + headlines.append(h) except: #if no settings just get top headlines headlines = newsapi.get_top_headlines() @@ -574,19 +577,20 @@ if __name__ == '__main__': logf = open("log.txt", "w") t = time.time() - + ''' updateStockPrices() print('finnhub:',time.time() -t) t = time.time() updateStockPricesIEX() print('iex:', time.time() -t) sys.exit() + ''' max_stocks = 200 max_crypto = 100 newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9') - update_frequencies = {'stocks':2, 'crypto':10, 'news':60, 'weather': 10} #minutes + update_frequencies = {'stocks':2, 'crypto':10, 'news':120, 'weather': 10} #minutes NY_zone = pytz.timezone('America/New_York') CET_zone = pytz.timezone('Europe/Berlin') diff --git a/csv/news_settings.csv b/csv/news_settings.csv deleted file mode 100644 index e69de29..0000000 diff --git a/csv/tickers.csv b/csv/tickers.csv index 48e357a..e5a8224 100644 --- a/csv/tickers.csv +++ b/csv/tickers.csv @@ -1,4 +1,4 @@ name,current,opening -MSFT,271.2101,268.865 -NFLX,533.325,533.55 -GOOG,2518.59,2535.45 +MSFT,270.51,270.69 +NFLX,529.11,534.0551 +GOOG,2509.69,2513.0713 diff --git a/display_gif.ppm b/display_gif.ppm new file mode 100644 index 0000000..c78d7a0 Binary files /dev/null and b/display_gif.ppm differ diff --git a/display_images/crypto.ppm b/display_images/crypto.ppm index 8485760..d4ad914 100755 Binary files a/display_images/crypto.ppm and b/display_images/crypto.ppm differ diff --git a/display_images/daily_weather.ppm b/display_images/daily_weather.ppm index fe836c1..a5fecee 100644 Binary files a/display_images/daily_weather.ppm and b/display_images/daily_weather.ppm differ diff --git a/display_images/display_gif.ppm b/display_images/display_gif.ppm new file mode 100644 index 0000000..c78d7a0 Binary files /dev/null and b/display_images/display_gif.ppm differ diff --git a/display_images/display_image.ppm b/display_images/display_image.ppm index bc7ea8b..2923789 100755 Binary files a/display_images/display_image.ppm and b/display_images/display_image.ppm differ diff --git a/display_images/forex.ppm b/display_images/forex.ppm index 4956a92..46a4813 100755 Binary files a/display_images/forex.ppm and b/display_images/forex.ppm differ diff --git a/display_images/league_games.ppm b/display_images/league_games.ppm index 1a6c10e..c3e7818 100644 Binary files a/display_images/league_games.ppm and b/display_images/league_games.ppm differ diff --git a/display_images/news.ppm b/display_images/news.ppm index aeeb5e4..92d756e 100755 Binary files a/display_images/news.ppm and b/display_images/news.ppm differ diff --git a/display_images/stocks.ppm b/display_images/stocks.ppm index 28a1241..20fc9d3 100755 Binary files a/display_images/stocks.ppm and b/display_images/stocks.ppm differ diff --git a/display_images/text.ppm b/display_images/text.ppm new file mode 100644 index 0000000..e7090f2 Binary files /dev/null and b/display_images/text.ppm differ diff --git a/display_images/today_weather.ppm b/display_images/today_weather.ppm index cdac52c..a5fecee 100644 Binary files a/display_images/today_weather.ppm and b/display_images/today_weather.ppm differ diff --git a/display_images/user_image.ppm b/display_images/user_image.ppm new file mode 100755 index 0000000..05e13eb Binary files /dev/null and b/display_images/user_image.ppm differ diff --git a/feature_titles/crypto.png b/feature_titles/crypto.png new file mode 100644 index 0000000..d50a514 Binary files /dev/null and b/feature_titles/crypto.png differ diff --git a/feature_titles/forex.png b/feature_titles/forex.png new file mode 100644 index 0000000..14f0032 Binary files /dev/null and b/feature_titles/forex.png differ diff --git a/feature_titles/gifs.png b/feature_titles/gifs.png new file mode 100644 index 0000000..45c8c34 Binary files /dev/null and b/feature_titles/gifs.png differ diff --git a/feature_titles/images.png b/feature_titles/images.png new file mode 100644 index 0000000..cdeab0f Binary files /dev/null and b/feature_titles/images.png differ diff --git a/feature_titles/message.png b/feature_titles/message.png new file mode 100644 index 0000000..057b3b5 Binary files /dev/null and b/feature_titles/message.png differ diff --git a/feature_titles/news.png b/feature_titles/news.png new file mode 100644 index 0000000..3e8785c Binary files /dev/null and b/feature_titles/news.png differ diff --git a/feature_titles/stocks.png b/feature_titles/stocks.png new file mode 100644 index 0000000..8d6d592 Binary files /dev/null and b/feature_titles/stocks.png differ diff --git a/feature_titles/weather.png b/feature_titles/weather.png new file mode 100644 index 0000000..066270f Binary files /dev/null and b/feature_titles/weather.png differ diff --git a/stockTicker.py b/stockTicker.py index fe0414c..6c12820 100644 --- a/stockTicker.py +++ b/stockTicker.py @@ -76,7 +76,7 @@ class StockTicker(): if (image.mode != "RGB"): - raise Exception("Currently, only RGB mode is supported for SetImage(). Please create images with mode 'RGB' or convert first with image = image.convert('RGB'). Pull requests to support more modes natively are also welcome :)") + image = image.convert('RGB') if unsafe: #In unsafe mode we directly acceshow to send commands to running python processs the underlying PIL image array @@ -198,7 +198,7 @@ class StockTicker(): def updateMultiple(self, options): for option in options: - if option not in ['display_image', 'display_gif']: + if option not in ['display_gif']: img = self.functions[option]() img.save('display_images/' + option + '.ppm') @@ -220,16 +220,16 @@ class StockTicker(): def scrollFunctionsAnimated(self, options, animation = 'continuous'): # scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed - self.updateMultiple([options[0]]) + self.updateMultiple(options) + - print('done update') kill = False i = 0 # keep track of which image we are displaying while True: update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],)) update_process.start() - print('display_images/' + options[i % len(options)] +'.ppm') + image = self.openImage('display_images/' + options[i % len(options)] +'.ppm') @@ -251,7 +251,7 @@ class StockTicker(): frame = 0 - pause_frames = int(1/self.delay) + pause_frames = int(0.5/self.delay) if animation == 'up': offset_y = 33 @@ -281,13 +281,13 @@ class StockTicker(): while pause_frames > 0: if pause_frames%frames == 0: - print(frame) + try: image.seek(frame) except EOFError: - print('finished') + frame = 0 image.seek(frame) frame +=1 @@ -305,13 +305,13 @@ class StockTicker(): while offset_y < 0: # for animation in gifs if offset_y%frames == 0: - print(frame) + try: image.seek(frame) except EOFError: - print('finished') + frame = 0 image.seek(frame) frame +=1 @@ -327,13 +327,13 @@ class StockTicker(): while pause_frames > 0: if pause_frames%frames == 0: - print(frame) + try: image.seek(frame) except EOFError: - print('finished') + frame = 0 image.seek(frame) frame +=1 @@ -350,13 +350,13 @@ class StockTicker(): # for animation in gifs if offset_x%frames == 0: - print(frame) + try: image.seek(frame) except EOFError: - print('finished') + frame = 0 image.seek(frame) frame +=1 @@ -421,12 +421,13 @@ class StockTicker(): text, r, g, b = next(CSV) f.close() - + + title_img = self.openImage('feature_titles/message.png') font = ImageFont.load("./fonts/texgyre-27.pil") img = self.textImage(text, font, int(r), int(g), int(b), True, w_buff = 50) - return img + return self.stitchImage([title_img, img]) def displayGIF(self, gif): # To iterate through the entire gif @@ -573,8 +574,8 @@ class StockTicker(): def getCryptoImage(self): - font = ImageFont.load("./fonts/texgyre-27.pil") - title_img = self.textImage('CRYPTO', font, matrix_height = True) + + title_img = self.openImage('feature_titles/crypto.png') image_list = [title_img] image_list.append(self.blank) @@ -624,8 +625,7 @@ class StockTicker(): return finalDisplayImage def getForexImage(self): - font = ImageFont.load("./fonts/texgyre-27.pil") - title_img = self.textImage('FOREX', font, matrix_height = True) + title_img = self.openImage('feature_titles/forex.png') image_list = [title_img] image_list.append(self.blank) @@ -685,8 +685,7 @@ class StockTicker(): return finalDisplayImage #Connect all the pieces togeather creating 1 long final stock image def getStockImage(self): - font = ImageFont.load("./fonts/texgyre-27.pil") - title_img = self.textImage('STOCKS', font, matrix_height = True) + title_img = self.openImage('feature_titles/stocks.png') image_list = [title_img] image_list.append(self.blank) @@ -731,8 +730,8 @@ class StockTicker(): def getNewsImage(self): - font = ImageFont.load("./fonts/texgyre-27.pil") - title_img = self.textImage('NEWS', font, matrix_height = True) + + title_img = self.openImage('feature_titles/news.png') @@ -762,6 +761,8 @@ class StockTicker(): headline = headline.replace("‘", "'") headline = headline.replace('“', '"') headline = headline.replace('”', '"') + headline = headline.replace('—', '-') + headline = headline.replace('–', '-') headline_img = self.textImage(headline, headline_font, matrix_height = True) source_img = self.textImage(source_date_times[i], source_font, r=255, g=255, b=0, matrix_height = True) @@ -994,7 +995,8 @@ class StockTicker(): f.close() - imgs = [] + title_img = self.openImage('feature_titles/weather.png') + imgs = [title_img] for location in locations: img = Image.new('RGB', (200, 32)) @@ -1091,10 +1093,9 @@ class StockTicker(): imgs.append(img) - font = ImageFont.load("./fonts/texgyre-27.pil") - title_img = self.textImage('WEATHER', font, matrix_height = True) + - return self.stitchImage([title_img] + imgs) + return self.stitchImage(imgs) def getDailyWeatherImageAlt(self): @@ -1246,8 +1247,8 @@ class StockTicker(): locations = line.split(',') f.close() - - imgs = [] + title_img = self.openImage('feature_titles/weather.png') + imgs = [title_img] for location in locations: img = Image.new('RGB', (1000, 32)) @@ -1419,10 +1420,10 @@ class StockTicker(): img1 = img.crop((0,0,x_offset ,32)) imgs.append(img1) # add the image text - font = ImageFont.load("./fonts/texgyre-27.pil") - title_img = self.textImage('WEATHER', font, matrix_height = True) - return self.stitchImage([title_img] + imgs) + + + return self.stitchImage(imgs) #Retrieve symbols and stock info from the csv file @@ -1518,8 +1519,11 @@ class StockTicker(): time.sleep(self.delay*1.1) def getUserImage(self): + + title_img = self.openImage('feature_titles/images.png') + image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_image.ppm')) - return image + return self.stitchImage([title_img, image]) def getUserGIF(self): gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_gif.ppm')) @@ -1632,7 +1636,7 @@ class StockTicker(): 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 #userSettings = ['stocks', 'crypto'] # these wil be read from csv, just for demo - #userSettings = [ 'forex', 'weather'] # these wil be read from csv, just for demo + userSettings = [ 'display_image', 'news'] # these wil be read from csv, just for demo self.scrollFunctionsAnimated(userSettings, animation = 'down') @@ -1647,7 +1651,8 @@ if __name__ == '__main__': #stock_ticker.process_msg(P') #stock_ticker.process_msg('G') - #stock_ticker.process_msg('A') + #stock_ticker.process_msg('f') + stock_ticker.process_msg('A')