feature titles added

This commit is contained in:
Neythen
2021-06-30 20:22:14 +01:00
parent 7cc9d1c832
commit 159c23bb3f
24 changed files with 54 additions and 45 deletions
+10 -6
View File
@@ -250,15 +250,18 @@ def updateCrypto():
def updateNews(): def updateNews():
max_per_cat = 10
try: try:
try: try:
#load user settings #load user settings
headlines = []
settings = json.load(open('csv/news_settings.json', 'r')) settings = json.load(open('csv/news_settings.json', 'r'))
print(settings) for setting in settings:
headlines = newsapi.get_top_headlines(**settings) h = newsapi.get_top_headlines(**setting)
if len(h) > max_per_cat:
h = h[0:max_per_cat]
headlines.append(h)
except: except:
#if no settings just get top headlines #if no settings just get top headlines
headlines = newsapi.get_top_headlines() headlines = newsapi.get_top_headlines()
@@ -574,19 +577,20 @@ if __name__ == '__main__':
logf = open("log.txt", "w") logf = open("log.txt", "w")
t = time.time() t = time.time()
'''
updateStockPrices() updateStockPrices()
print('finnhub:',time.time() -t) print('finnhub:',time.time() -t)
t = time.time() t = time.time()
updateStockPricesIEX() updateStockPricesIEX()
print('iex:', time.time() -t) print('iex:', time.time() -t)
sys.exit() sys.exit()
'''
max_stocks = 200 max_stocks = 200
max_crypto = 100 max_crypto = 100
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9') 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') NY_zone = pytz.timezone('America/New_York')
CET_zone = pytz.timezone('Europe/Berlin') CET_zone = pytz.timezone('Europe/Berlin')
View File
+3 -3
View File
@@ -1,4 +1,4 @@
name,current,opening name,current,opening
MSFT,271.2101,268.865 MSFT,270.51,270.69
NFLX,533.325,533.55 NFLX,529.11,534.0551
GOOG,2518.59,2535.45 GOOG,2509.69,2513.0713
1 name current opening
2 MSFT 271.2101 270.51 268.865 270.69
3 NFLX 533.325 529.11 533.55 534.0551
4 GOOG 2518.59 2509.69 2535.45 2513.0713
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 747 B

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 488 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 398 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 616 B

+41 -36
View File
@@ -76,7 +76,7 @@ class StockTicker():
if (image.mode != "RGB"): 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: if unsafe:
#In unsafe mode we directly acceshow to send commands to running python processs the underlying PIL image array #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): def updateMultiple(self, options):
for option in options: for option in options:
if option not in ['display_image', 'display_gif']: if option not in ['display_gif']:
img = self.functions[option]() img = self.functions[option]()
img.save('display_images/' + option + '.ppm') img.save('display_images/' + option + '.ppm')
@@ -220,16 +220,16 @@ class StockTicker():
def scrollFunctionsAnimated(self, options, animation = 'continuous'): def scrollFunctionsAnimated(self, options, animation = 'continuous'):
# scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed # 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 kill = False
i = 0 # keep track of which image we are displaying i = 0 # keep track of which image we are displaying
while True: while True:
update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],)) update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],))
update_process.start() update_process.start()
print('display_images/' + options[i % len(options)] +'.ppm')
image = self.openImage('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 frame = 0
pause_frames = int(1/self.delay) pause_frames = int(0.5/self.delay)
if animation == 'up': if animation == 'up':
offset_y = 33 offset_y = 33
@@ -281,13 +281,13 @@ class StockTicker():
while pause_frames > 0: while pause_frames > 0:
if pause_frames%frames == 0: if pause_frames%frames == 0:
print(frame)
try: try:
image.seek(frame) image.seek(frame)
except EOFError: except EOFError:
print('finished')
frame = 0 frame = 0
image.seek(frame) image.seek(frame)
frame +=1 frame +=1
@@ -305,13 +305,13 @@ class StockTicker():
while offset_y < 0: while offset_y < 0:
# for animation in gifs # for animation in gifs
if offset_y%frames == 0: if offset_y%frames == 0:
print(frame)
try: try:
image.seek(frame) image.seek(frame)
except EOFError: except EOFError:
print('finished')
frame = 0 frame = 0
image.seek(frame) image.seek(frame)
frame +=1 frame +=1
@@ -327,13 +327,13 @@ class StockTicker():
while pause_frames > 0: while pause_frames > 0:
if pause_frames%frames == 0: if pause_frames%frames == 0:
print(frame)
try: try:
image.seek(frame) image.seek(frame)
except EOFError: except EOFError:
print('finished')
frame = 0 frame = 0
image.seek(frame) image.seek(frame)
frame +=1 frame +=1
@@ -350,13 +350,13 @@ class StockTicker():
# for animation in gifs # for animation in gifs
if offset_x%frames == 0: if offset_x%frames == 0:
print(frame)
try: try:
image.seek(frame) image.seek(frame)
except EOFError: except EOFError:
print('finished')
frame = 0 frame = 0
image.seek(frame) image.seek(frame)
frame +=1 frame +=1
@@ -421,12 +421,13 @@ class StockTicker():
text, r, g, b = next(CSV) text, r, g, b = next(CSV)
f.close() f.close()
title_img = self.openImage('feature_titles/message.png')
font = ImageFont.load("./fonts/texgyre-27.pil") font = ImageFont.load("./fonts/texgyre-27.pil")
img = self.textImage(text, font, int(r), int(g), int(b), True, w_buff = 50) 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): def displayGIF(self, gif):
# To iterate through the entire gif # To iterate through the entire gif
@@ -573,8 +574,8 @@ class StockTicker():
def getCryptoImage(self): 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 = [title_img]
image_list.append(self.blank) image_list.append(self.blank)
@@ -624,8 +625,7 @@ class StockTicker():
return finalDisplayImage return finalDisplayImage
def getForexImage(self): def getForexImage(self):
font = ImageFont.load("./fonts/texgyre-27.pil") title_img = self.openImage('feature_titles/forex.png')
title_img = self.textImage('FOREX', font, matrix_height = True)
image_list = [title_img] image_list = [title_img]
image_list.append(self.blank) image_list.append(self.blank)
@@ -685,8 +685,7 @@ class StockTicker():
return finalDisplayImage return finalDisplayImage
#Connect all the pieces togeather creating 1 long final stock image #Connect all the pieces togeather creating 1 long final stock image
def getStockImage(self): def getStockImage(self):
font = ImageFont.load("./fonts/texgyre-27.pil") title_img = self.openImage('feature_titles/stocks.png')
title_img = self.textImage('STOCKS', font, matrix_height = True)
image_list = [title_img] image_list = [title_img]
image_list.append(self.blank) image_list.append(self.blank)
@@ -731,8 +730,8 @@ class StockTicker():
def getNewsImage(self): 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 = headline.replace('', '"')
headline = headline.replace('', '-')
headline = headline.replace('', '-')
headline_img = self.textImage(headline, headline_font, matrix_height = True) 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) 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() f.close()
imgs = [] title_img = self.openImage('feature_titles/weather.png')
imgs = [title_img]
for location in locations: for location in locations:
img = Image.new('RGB', (200, 32)) img = Image.new('RGB', (200, 32))
@@ -1091,10 +1093,9 @@ class StockTicker():
imgs.append(img) 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): def getDailyWeatherImageAlt(self):
@@ -1246,8 +1247,8 @@ class StockTicker():
locations = line.split(',') locations = line.split(',')
f.close() f.close()
title_img = self.openImage('feature_titles/weather.png')
imgs = [] imgs = [title_img]
for location in locations: for location in locations:
img = Image.new('RGB', (1000, 32)) img = Image.new('RGB', (1000, 32))
@@ -1419,10 +1420,10 @@ class StockTicker():
img1 = img.crop((0,0,x_offset ,32)) img1 = img.crop((0,0,x_offset ,32))
imgs.append(img1) imgs.append(img1)
# add the image text # 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 #Retrieve symbols and stock info from the csv file
@@ -1518,8 +1519,11 @@ class StockTicker():
time.sleep(self.delay*1.1) time.sleep(self.delay*1.1)
def getUserImage(self): 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')) 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): def getUserGIF(self):
gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/display_gif.ppm')) 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 = ['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 = ['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') self.scrollFunctionsAnimated(userSettings, animation = 'down')
@@ -1647,7 +1651,8 @@ if __name__ == '__main__':
#stock_ticker.process_msg(P') #stock_ticker.process_msg(P')
#stock_ticker.process_msg('G') #stock_ticker.process_msg('G')
#stock_ticker.process_msg('A') #stock_ticker.process_msg('f')
stock_ticker.process_msg('A')