From 1326007787f5abbfa843defa37b335363bedfc2b Mon Sep 17 00:00:00 2001 From: Neythen Date: Tue, 12 Oct 2021 20:52:52 +0100 Subject: [PATCH] added all settings for messages, gifs, images and professional --- csv/crypto_settings.json | 2 +- csv/display_settings.json | 2 +- csv/forex_settings.json | 2 +- csv/image_settings.json | 2 +- csv/stocks_settings.json | 2 +- server.py | 4 +- stockTicker.py | 299 +++++++++++++++++++++++--------------- templates/index.html | 124 ++++++++-------- 8 files changed, 246 insertions(+), 191 deletions(-) diff --git a/csv/crypto_settings.json b/csv/crypto_settings.json index e01e2e1..5e37ee2 100644 --- a/csv/crypto_settings.json +++ b/csv/crypto_settings.json @@ -1 +1 @@ -{"feature": "Stocks", "speed": "medium", "animation": "continuous", "percent": false, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"NEO,USD": {"current": 43.42, "24hr_change": -3.963839231643678}, "BTC,USD": {"current": 49343, "24hr_change": 0.902025932223419}, "ETH,BTC": {"current": 0.06930671, "24hr_change": -1.7367682270496585}, "ADA,GBP": {"current": 1.62, "24hr_change": -3.549646457710461}}} \ No newline at end of file +{"feature": "Stocks", "speed": "medium", "animation": "traditional", "percent": false, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"NEO,USD": {"current": 43.42, "24hr_change": -3.963839231643678}, "BTC,USD": {"current": 49343, "24hr_change": 0.902025932223419}, "ETH,BTC": {"current": 0.06930671, "24hr_change": -1.7367682270496585}, "ADA,GBP": {"current": 1.62, "24hr_change": -3.549646457710461}}} \ No newline at end of file diff --git a/csv/display_settings.json b/csv/display_settings.json index 43da6fc..02623e2 100755 --- a/csv/display_settings.json +++ b/csv/display_settings.json @@ -1 +1 @@ -["Custom Messages"] \ No newline at end of file +["Stocks", "Crypto", "Forex"] \ No newline at end of file diff --git a/csv/forex_settings.json b/csv/forex_settings.json index 536758f..3e96587 100644 --- a/csv/forex_settings.json +++ b/csv/forex_settings.json @@ -1 +1 @@ -{"feature": "Stocks", "speed": "medium", "animation": "continuous", "percent": false, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"NZD,GBP": {"current": 1.9471, "24hr_change": 0.0029000000000001247}, "CAD,USD": {"current": 1.271, "24hr_change": 0.0033999999999998476}}} \ No newline at end of file +{"feature": "Stocks", "speed": "fast", "animation": "down", "percent": false, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"NZD,GBP": {"current": 1.9471, "24hr_change": 0.0029000000000001247}, "CAD,USD": {"current": 1.271, "24hr_change": 0.0033999999999998476}}} \ No newline at end of file diff --git a/csv/image_settings.json b/csv/image_settings.json index 98f75f3..0c626ae 100644 --- a/csv/image_settings.json +++ b/csv/image_settings.json @@ -1 +1 @@ -{"speed": "medium", "animation": "continuous", "title": true, "pause": "", "images": ["XOM.png", "ZBRA.png"]} \ No newline at end of file +{"speed": "medium", "animation": "traditional", "title": true, "pause": "3", "images": ["XOM.png", "ZBRA.png"]} \ No newline at end of file diff --git a/csv/stocks_settings.json b/csv/stocks_settings.json index 100b5c1..e702cc4 100644 --- a/csv/stocks_settings.json +++ b/csv/stocks_settings.json @@ -1 +1 @@ -{"feature": "Stocks", "speed": "medium", "animation": "continuous", "percent": true, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"MSFT": {"current": 282.63, "opening": 287.28}, "GOOG": {"current": 2665.2, "opening": 2713.99}}} \ No newline at end of file +{"feature": "Stocks", "speed": "slow", "animation": "down", "percent": true, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"MSFT": {"current": 282.63, "opening": 287.28}, "GOOG": {"current": 2665.2, "opening": 2713.99}}} \ No newline at end of file diff --git a/server.py b/server.py index e639fe4..78cbd10 100644 --- a/server.py +++ b/server.py @@ -77,6 +77,7 @@ def index(): team_stats = json.load(open('csv/league_tables.json', 'r')) image_settings = json.load(open('csv/image_settings.json', 'r')) GIF_settings = json.load(open('csv/GIF_settings.json', 'r')) + message_settings = json.load(open('csv/message_settings.json', 'r')) templateData = { @@ -93,7 +94,8 @@ def index(): 'live_games': live_games, 'team_stats': team_stats, 'image_settings':image_settings, - 'GIF_settings':GIF_settings + 'GIF_settings':GIF_settings, + 'message_settings':message_settings } return render_template('index.html', **templateData) diff --git a/stockTicker.py b/stockTicker.py index bdb175e..85e140f 100644 --- a/stockTicker.py +++ b/stockTicker.py @@ -39,7 +39,7 @@ class StockTicker(): def __init__(self): #Define global resources self.symbols = [] - + self.delay = 0.02 self.greenORred = (255, 255, 255) #self.blank = Image.open('logos/blank.png') self.blank = Image.new('RGB', (10, 32)) @@ -68,8 +68,13 @@ class StockTicker(): 'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional, 'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional} - - + 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', + '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'} def openImage(self, image_file): @@ -303,13 +308,23 @@ class StockTicker(): sys.stdout.flush() pass return kill - + + def set_delay(self,speed): + if speed.lower() == 'slow': + self.delay = 0.04 + elif speed.lower() == 'medium': + self.delay = 0.02 + elif speed.lower() == 'fast': + self.delay = 0.01 + return self.delay + + def scrollFunctionsAnimated(self, options, animation = 'down'): # scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed self.updateMultiple([options[0]]) - + kill = False i = 0 # keep track of which image we are displaying @@ -319,7 +334,11 @@ class StockTicker(): update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],)) update_process.start() - self.delay = 0.02 + settings = json.load(open(self.JSONs[options[(i) % len(options)]])) + + self.set_delay(settings['speed']) + animation = settings['animation'].lower() + if options[i % len(options)] == 'Custom Images': images = self.getUserImages() @@ -392,14 +411,165 @@ class StockTicker(): if kill: break - - kill = self.scrollImage(image, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] == 'Custom GIFs') + try: + pause = float(settings['pause']) + except: + pause = 0 + pause_frames = int(float(pause)/self.delay) + kill = self.scrollImage(image, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] == 'Custom GIFs', pause_frames = pause_frames) if kill: break if kill:break update_process.join() i+=1 + + def scrollProfessionalAnimated(self, options, animation = 'on'): + + # scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed + + + + self.updateMultiple(options[0:2]) + + kill = False + i1 = 0 # keep track of which image we are displaying + i2 = 1 # keep track of which image we are displaying + + self.double_buffer = self.matrix.CreateFrameCanvas() + update_process = Process(target = self.updateMultiple, args = ([options[(max(i1,i2)+1) % len(options)]],)) + update_process.start() + + image1 = self.openImage('./display_images/' + options[i1 % len(options)] +'.ppm') + image1 = image1.convert('RGB') + + print(options[i2 % len(options)]) + image2 = self.openImage('./display_images/' + options[i2 % len(options)] +'.ppm') + image2 = image2.convert('RGB') + + + settings1 = json.load(open(self.JSONs[options[0]])) + + delay_t1 = self.set_delay(settings1['speed']) + animation1 = settings1['animation'].lower() + + settings2 = json.load(open(self.JSONs[options[1]])) + delay_t2 = self.set_delay(settings2['speed']) + animation2 = settings2['animation'].lower() + + if animation1 == 'traditional': + offset_y1 = 0 + offset_x1 = 128 + else: + offset_y1 = -16 + offset_x1 = 0 + + if animation2 == 'traditional': + offset_y2 = 16 + offset_x2 = 128 + else: + offset_y2 = 32 + offset_x2 = 0 + + + frame_skip = int((1/15)/self.delay) #controls how fast gifs run + self.frame = 0 + + img_width1, img_height1 = image1.size + img_width2, img_height2 = image2.size + kill = False + + delay_t1 = 0.02 + delay_t2 = 0.025 + update_t1 = time.time() + update_t2 = time.time() + while True: + + if offset_x1 < -(img_width1+1): + i1 = max(i1, i2) + 1 + settings1 = json.load(open(self.JSONs[options[i1 % len(options)]])) + + delay_t1 = self.set_delay(settings1['speed']) + animation1 = settings1['animation'].lower() + + if animation1 == 'traditional': + offset_y1 = 0 + offset_x1 = 128 + else: + offset_y1 = -16 + offset_x1 = 0 + + update_process.join() + update_process = Process(target = self.updateMultiple, args = ([options[i1 % len(options)]],)) + update_process.start() + image1 = self.openImage('./display_images/' + options[i1 % len(options)] +'.ppm') + image1 = image1.convert('RGB') + img_width1, img_height1 = image1.size + + if offset_x2 < -(img_width2+1): + i2 = max(i1, i2) + 1 + settings2 = json.load(open(self.JSONs[options[(i2) % len(options)]])) + delay_t2 = self.set_delay(settings2['speed']) + animation2 = settings2['animation'].lower() + + if animation2 == 'traditional': + offset_y2 = 16 + offset_x2 = 128 + else: + offset_y2 = 32 + offset_x2 = 0 + + + update_process.join() + update_process = Process(target = self.updateMultiple, args = ([options[i2 % len(options)]],)) + update_process.start() + image2 = self.openImage('./display_images/' + options[i2 % len(options)] +'.ppm') + image2 = image2.convert('RGB') + img_width2, img_height2 = image2.size + + + if time.time() - update_t1 > delay_t1: + update_t1 = time.time() + if offset_y1 < 0: + offset_y1+=1 + else: + offset_x1 -= 1 + + if time.time() - update_t2 > delay_t2: + update_t2 = time.time() + if offset_y2 > 16: + offset_y2-=1 + else: + offset_x2 -= 1 + + if kill: break + + #image = image.convert('RGB') + + + + self.double_buffer.SetImage(image1, offset_x1, offset_y1) + self.double_buffer.SetImage(image2, offset_x2, offset_y2) + + buff = 0 + + # remove the ppixels behind the image, to stop trailing + self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer) + for y in range(16): + self.matrix.SetPixel(offset_x1 + img_width1 +1 , y , 0,0,0) + self.matrix.SetPixel(offset_x1 + img_width1 , y , 0,0,0) + for y in range(16,32): + self.matrix.SetPixel(offset_x2 + img_width2 +1 , y , 0,0,0) + self.matrix.SetPixel(offset_x2 + img_width2 , y , 0,0,0) + + + + kill = self.checkKilled() + + if kill: break + + + if kill: break def scrollMultiple(self, animation = 'down'): # scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed @@ -2060,118 +2230,7 @@ class StockTicker(): if kill: break - def scrollProfessionalAnimated(self, options, animation = 'on'): - - # scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed - - - print(options[0:2]) - self.updateMultiple(options[0:2]) - - kill = False - i1 = 0 # keep track of which image we are displaying - i2 = 1 # keep track of which image we are displaying - - self.double_buffer = self.matrix.CreateFrameCanvas() - update_process = Process(target = self.updateMultiple, args = ([options[(max(i1,i2)+1) % len(options)]],)) - update_process.start() - - image1 = self.openImage('./display_images/' + options[i1 % len(options)] +'.ppm') - image1 = image1.convert('RGB') - - print(options[i2 % len(options)]) - image2 = self.openImage('./display_images/' + options[i2 % len(options)] +'.ppm') - image2 = image2.convert('RGB') - - - - offset_x1 = 0 - offset_x2 = 0 - - offset_y1 = -16 - offset_y2 = 32 - - frame_skip = int((1/15)/self.delay) #controls how fast gifs run - self.frame = 0 - - img_width1, img_height1 = image1.size - img_width2, img_height2 = image2.size - kill = False - - delay_t1 = 0.02 - delay_t2 = 0.025 - update_t1 = time.time() - update_t2 = time.time() - while True: - - if offset_x1 < -(img_width1+1): - - i1 = max(i1, i2) + 1 - offset_x1 = 0 - offset_y1 = -16 - update_process.join() - update_process = Process(target = self.updateMultiple, args = ([options[(max(i1,i2)+1) % len(options)]],)) - update_process.start() - image1 = self.openImage('./display_images/' + options[i1 % len(options)] +'.ppm') - image1 = image1.convert('RGB') - img_width1, img_height1 = image1.size - - - - if offset_x2 < -(img_width2+1): - - i2 = max(i1, i2) + 1 - offset_x2 = 0 - offset_y2 = 32 - update_process.join() - update_process = Process(target = self.updateMultiple, args = ([options[(max(i1,i2)+1) % len(options)]],)) - update_process.start() - image2 = self.openImage('./display_images/' + options[i2 % len(options)] +'.ppm') - image2 = image2.convert('RGB') - img_width2, img_height2 = image2.size - - if time.time() - update_t1 > delay_t1: - update_t1 = time.time() - if offset_y1 < 0: - offset_y1+=1 - else: - offset_x1 -= 1 - - if time.time() - update_t2 > delay_t2: - update_t2 = time.time() - if offset_y2 > 16: - offset_y2-=1 - else: - offset_x2 -= 1 - - if kill: break - - #image = image.convert('RGB') - - - - self.double_buffer.SetImage(image1, offset_x1, offset_y1) - self.double_buffer.SetImage(image2, offset_x2, offset_y2) - - buff = 0 - - # remove the ppixels behind the image, to stop trailing - self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer) - for y in range(16): - self.matrix.SetPixel(offset_x1 + img_width1 +1 , y , 0,0,0) - self.matrix.SetPixel(offset_x1 + img_width1 , y , 0,0,0) - for y in range(16,32): - self.matrix.SetPixel(offset_x2 + img_width2 +1 , y , 0,0,0) - self.matrix.SetPixel(offset_x2 + img_width2 , y , 0,0,0) - - - - kill = self.checkKilled() - - if kill: break - - - if kill: break + def process_msg(self, msg): diff --git a/templates/index.html b/templates/index.html index 930cd2d..144443f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -280,11 +280,12 @@
@@ -483,11 +484,10 @@
@@ -684,11 +684,9 @@
@@ -887,11 +885,10 @@
@@ -1073,11 +1070,10 @@
@@ -1277,11 +1273,10 @@
@@ -1450,11 +1445,10 @@
@@ -1577,11 +1571,10 @@
@@ -1704,11 +1697,10 @@
@@ -1830,11 +1822,10 @@
@@ -1977,11 +1968,10 @@
@@ -2130,11 +2120,10 @@
@@ -2282,11 +2271,10 @@
@@ -2442,7 +2430,9 @@ type="checkbox" value="" id="flexCheckChecked29" - checked + {% if message_settings.title%} + checked + {%endif%} /> @@ -2454,6 +2444,10 @@ id="messages-features" class="display-features-list text-dark message-list" > + + {% for f in message_settings.messages %} +
  • {{f.name}}
  • + {% endfor%}