From 3c0907baf62cb87c3f30bd35f54521d67b46cd43 Mon Sep 17 00:00:00 2001 From: Neythen Date: Tue, 27 Jul 2021 18:33:02 +0100 Subject: [PATCH] multiple images and gifs --- csv/crypto.csv | 6 +- csv/currency.json | 2 +- csv/current_weather.json | 2 +- csv/daily_weather.json | 2 +- csv/last_updates.json | 2 +- csv/multiple.csv | 4 ++ csv/news.csv | 40 +++++------ csv/tickers.csv | 6 +- server.py | 5 ++ stockTicker.py | 152 ++++++++++++++++++++++++++++++++------- templates/index.html | 1 + 11 files changed, 165 insertions(+), 57 deletions(-) create mode 100644 csv/multiple.csv diff --git a/csv/crypto.csv b/csv/crypto.csv index aa9fb43..decc59f 100644 --- a/csv/crypto.csv +++ b/csv/crypto.csv @@ -1,4 +1,4 @@ symbol,name,base,current,24hr change -BTC,bitcoin,usd,40270,16.560179943187396 -ETH,ethereum,gbp,1750.78,11.871734531689802 -DOGE,dogecoin,usd,0.22635,14.743047682205162 +BTC,bitcoin,usd,37791,-3.5064161412834833 +ETH,ethereum,gbp,1608.87,-5.529203500553435 +DOGE,dogecoin,usd,0.199271,-10.734868356523817 diff --git a/csv/currency.json b/csv/currency.json index 24cca5f..665b6ae 100644 --- a/csv/currency.json +++ b/csv/currency.json @@ -1 +1 @@ -["USD", {"AUD": [1.3553, 1.3667], "CAD": [1.2551, 1.2684], "CHF": [0.91966, 0.92151], "EUR": [0.84926, 0.84947], "GBP": [0.72665, 0.73363], "JPY": [110.26, 110.12], "NZD": [1.4358, 1.4444]}] \ No newline at end of file +["USD", {"AUD": [1.3572, 1.3583], "CAD": [1.2565, 1.256], "CHF": [0.91499, 0.91847], "EUR": [0.84674, 0.84839], "GBP": [0.72399, 0.7251], "JPY": [110.06, 110.33], "NZD": [1.4357, 1.4328]}] \ No newline at end of file diff --git a/csv/current_weather.json b/csv/current_weather.json index 80aba32..e9b0a80 100644 --- a/csv/current_weather.json +++ b/csv/current_weather.json @@ -1 +1 @@ -[{"main_weather": "Clouds", "description": "overcast clouds", "temp": 29.61, "min_temp": 29.36, "max_temp": 32.34, "feels_like": 36.61, "humidity": 90, "clouds": 100, "wind_speed": 0.45, "wind_direction": 200, "visibility": 10000, "uv": 0, "rain_chance": 0.73}, {"main_weather": "Clouds", "description": "broken clouds", "temp": 21.11, "min_temp": 14.98, "max_temp": 24.47, "feels_like": 21.23, "humidity": 75, "clouds": 80, "wind_speed": 4.12, "wind_direction": 210, "visibility": 10000, "uv": 0, "rain_chance": 0.12}] \ No newline at end of file +[{"main_weather": "Clouds", "description": "broken clouds", "temp": 29.92, "min_temp": 29.34, "max_temp": 30.71, "feels_like": 36.92, "humidity": 88, "clouds": 78, "wind_speed": 0.45, "wind_direction": 299, "visibility": 10000, "uv": 0, "rain_chance": 0.72}, {"main_weather": "Clouds", "description": "few clouds", "temp": 20.29, "min_temp": 16.54, "max_temp": 20.41, "feels_like": 20.33, "humidity": 75, "clouds": 20, "wind_speed": 0.45, "wind_direction": 278, "visibility": 10000, "uv": 0.23, "rain_chance": 0.84}] \ No newline at end of file diff --git a/csv/daily_weather.json b/csv/daily_weather.json index f152c85..c8dc6fe 100644 --- a/csv/daily_weather.json +++ b/csv/daily_weather.json @@ -1 +1 @@ -[[{"main_weather": "Rain", "description": "light rain", "min_temp": 29.36, "max_temp": 32.34}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 29.45, "max_temp": 31.59}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 29.04, "max_temp": 30.82}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.75, "max_temp": 29.42}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.77, "max_temp": 28.47}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.04, "max_temp": 28.25}, {"main_weather": "Rain", "description": "light rain", "min_temp": 27.27, "max_temp": 30.37}, {"main_weather": "Rain", "description": "light rain", "min_temp": 29.15, "max_temp": 31.87}], [{"main_weather": "Rain", "description": "light rain", "min_temp": 14.98, "max_temp": 24.47}, {"main_weather": "Rain", "description": "light rain", "min_temp": 15.59, "max_temp": 20.24}, {"main_weather": "Rain", "description": "light rain", "min_temp": 13.65, "max_temp": 20.3}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 12.01, "max_temp": 20.01}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 13.09, "max_temp": 20.15}, {"main_weather": "Rain", "description": "light rain", "min_temp": 13.43, "max_temp": 21.97}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 12.99, "max_temp": 22.6}, {"main_weather": "Rain", "description": "light rain", "min_temp": 14.44, "max_temp": 21.85}]] \ No newline at end of file +[[{"main_weather": "Rain", "description": "light rain", "min_temp": 29.34, "max_temp": 30.71}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.88, "max_temp": 30.28}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 28.76, "max_temp": 30.43}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.46, "max_temp": 29.34}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 26.98, "max_temp": 28.05}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 27.66, "max_temp": 30.29}, {"main_weather": "Rain", "description": "light rain", "min_temp": 29.07, "max_temp": 31.98}, {"main_weather": "Rain", "description": "light rain", "min_temp": 29.71, "max_temp": 31.97}], [{"main_weather": "Rain", "description": "light rain", "min_temp": 16.54, "max_temp": 20.41}, {"main_weather": "Rain", "description": "light rain", "min_temp": 14.1, "max_temp": 20.41}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 12.28, "max_temp": 20.13}, {"main_weather": "Rain", "description": "light rain", "min_temp": 13.47, "max_temp": 15}, {"main_weather": "Rain", "description": "light rain", "min_temp": 13.98, "max_temp": 19.48}, {"main_weather": "Rain", "description": "light rain", "min_temp": 12.63, "max_temp": 21.45}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 13.76, "max_temp": 21.62}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 15.08, "max_temp": 23.41}]] \ No newline at end of file diff --git a/csv/last_updates.json b/csv/last_updates.json index 60b443a..f1d1f2e 100644 --- a/csv/last_updates.json +++ b/csv/last_updates.json @@ -1 +1 @@ -{"stocks": "26/07/2021 15:54:43", "crypto": "26/07/2021 15:54:43", "news": "26/07/2021 15:54:43", "weather": "26/07/2021 15:54:43", "forex": "26/07/2021 21:54:43", "sports": "26/07/2021 15:54:43"} \ No newline at end of file +{"stocks": "27/07/2021 13:30:45", "crypto": "27/07/2021 13:30:48", "news": "27/07/2021 13:30:50", "weather": "27/07/2021 13:30:49", "forex": "27/07/2021 19:30:53", "sports": "27/07/2021 13:30:50"} \ No newline at end of file diff --git a/csv/multiple.csv b/csv/multiple.csv new file mode 100644 index 0000000..06ef435 --- /dev/null +++ b/csv/multiple.csv @@ -0,0 +1,4 @@ +type,content,pause(secs) +text,hello world!,0 +image,/home/pi/Desktop/stock_ticker/logos/crypto/BTC.png,5 +gif,/home/pi/Desktop/stock_ticker/gifs/close.gif,15 diff --git a/csv/news.csv b/csv/news.csv index 598f10b..3a0940b 100644 --- a/csv/news.csv +++ b/csv/news.csv @@ -1,21 +1,21 @@ headline,source,date,time -Green Bay Packers GM Brian Gutekunst 'remains hopeful' for positive resolution with QB Aaron Rodgers - ESPN,ESPN,2021-07-26,18:32:46Z -Is 25C too hot? How we decide what qualifies as a heatwave - Stuff.co.nz,Stuff.co.nz,2021-07-26,18:29:00Z -COVID-19: More testing sites and self-isolation exemption list in England expanded in bid to ease 'pingdemic' - Sky News,Sky.com,2021-07-26,18:28:11Z -12 times iPhones beat Androids - The Nation Newspaper ,The Nation Newspaper ,2021-07-26,18:20:37Z -Large meteor lights up skies in Norway - CTV News,Ctvnews.ca,2021-07-26,18:14:16Z -Summer Olympics 2021: What to Watch for on Day 4 in Tokyo - Bleacher Report,Bleacher Report,2021-07-26,18:11:43Z -COVID-19 live updates: Savannah reinstates masks indoors^ Orlando in 'crisis mode' - ABC News,ABC News,2021-07-26,18:06:00Z -Tunisia’s Democracy Verges on Dissolution as President Moves to Take Control - The New York Times,New York Times,2021-07-26,18:04:29Z -Tokyo Olympics DAY 4 India Results: Bad day at office - InsideSport,InsideSport,2021-07-26,18:03:34Z -Kanye West’s New Album Donda Will Be Released August 6^ A Rep Confirms - Pitchfork,Pitchfork,2021-07-26,17:57:12Z -Psaki: Biden doesn't want to 'fight' Fox after Trump 'destroyed trust in media' - Business Insider,Business Insider,2021-07-26,17:56:13Z -Scientists including India astronomers spot unique Gamma-ray burst using NASA’s space telescope - Times of India,The Times of India,2021-07-26,17:53:00Z -Manchester United in final negotiations to sign Raphaël Varane for around £40m - The Guardian,The Guardian,2021-07-26,17:49:00Z -#UnrestSA: West Rand politician Bruce Nimmerhoudt charged with terrorism - News24,News24,2021-07-26,17:47:52Z -SA women plan class action lawsuit over implant used to treat incontinence - News24,News24,2021-07-26,17:47:46Z -Coronavirus: 11 new COVID-19 cases in Manitoba^ Winnipeg's test positivity rate below two per cent - CTV News Winnipeg,Ctvnews.ca,2021-07-26,17:46:29Z -Tokyo 2020: Mona McSharry’s achievement a paradigm shift for Irish swimming - The Irish Times,The Irish Times,2021-07-26,17:44:27Z -Mount Sinai researchers use cerebral organoids to study frontotemporal dementia - News-Medical.Net,News-Medical.Net,2021-07-26,17:44:00Z -Texas^ Oklahoma Indicate They'll Leave the Big 12 for the SEC - The New York Times,New York Times,2021-07-26,17:40:26Z -How ‘Baba Ijesha’ defiled my foster daughter while watching cartoons — Princess - The Nation Newspaper ,The Nation Newspaper ,2021-07-26,17:38:26Z +Tokyo 2020 Olympics: Osaka story ended by Vondrousova^ and Bencic ousts Krejcikova - The Sport Review,The Sport Review,2021-07-27,16:34:00Z +1st alarm raised as Marikina River water level breaches 15 meters - ABS-CBN News,Abs-cbn.com,2021-07-27,16:23:00Z +Aaron Rodgers back to work as icy Packers relationship appears to thaw - Fox News,Fox News,2021-07-27,16:09:19Z +Lake Tahoe plane crash: Twin-engine jet accident kills all passengers^ FAA says - Fox News,Fox News,2021-07-27,16:08:40Z +Alex Telles: Manchester United left-back out until September with injury^ says Ole Gunnar Solskjaer - Sky Sports,Sky Sports,2021-07-27,16:07:30Z +Disney's Jungle Cruise Review - IGN,IGN,2021-07-27,16:00:34Z +BOP deficit widens to $312 million in June - Philstar.com,Philippine Star,2021-07-27,16:00:00Z +Vista Land optimistic on growth prospects - Philstar.com,Philippine Star,2021-07-27,16:00:00Z +Phoenix Petroleum settles P3 billion commercial papers - Philstar.com,Philippine Star,2021-07-27,16:00:00Z +Facebook assembles expert team to build 'metaverse' - Taipei Times,Taipei Times,2021-07-27,16:00:00Z +Emily Blunt and the Rock Drip With Charismatic Chemistry in Disney's Jungle Cruise - Gizmodo,Gizmodo.com,2021-07-27,16:00:00Z +Exclusive: Rakesh Asthana appointed Delhi Police Commissioner - Hindustan Times,Hindustan Times,2021-07-27,15:54:36Z +Simone Biles says mental health issues behind Tokyo Olympics withdrawal as she admits: 'I just didn't want to go on' - Sky News,Sky.com,2021-07-27,15:52:08Z +Mamata Banerjee meets PM Modi^ calls for all-party meeting to discuss Pegasus issue - The Indian Express,The Indian Express,2021-07-27,15:51:49Z +Trump could be forced to testify over Capitol riot^ says Liz Cheney: ‘This is not a game’ - The Independent,Independent,2021-07-27,15:51:28Z +A First Look At The Fitbit Charge 5? - Forbes,Forbes,2021-07-27,15:47:38Z +Facebook upgrades Oculus Quest 2 storage and recalls foam face masks - The Verge,The Verge,2021-07-27,15:41:36Z +Boris Johnson says stop and search policy ‘kind and loving’ way to get weapons off streets - The Independent,Independent,2021-07-27,15:41:05Z +Sinema meets with Biden as bipartisan talks teeter - POLITICO,Politico,2021-07-27,15:41:02Z +Nova Scotia man identified as Ottawa homicide victim - CBC.ca,CBC News,2021-07-27,15:40:40Z diff --git a/csv/tickers.csv b/csv/tickers.csv index e438cd8..cb05573 100644 --- a/csv/tickers.csv +++ b/csv/tickers.csv @@ -1,4 +1,4 @@ name,current,opening -MSFT,289.33,289 -NFLX,517.2,514.85 -GOOG,2783.82,2764.03 +MSFT,283.47,289.34 +NFLX,515.31,518.95 +GOOG,2706.565,2801.15 diff --git a/server.py b/server.py index 85b5915..b140141 100644 --- a/server.py +++ b/server.py @@ -323,6 +323,11 @@ def matrix(): ticker.sendline('K') ticker.sendline('A') + elif "Multiple" in request.form: + + ticker.sendline('K') + ticker.sendline('+') + elif "Stop Display" in request.form: diff --git a/stockTicker.py b/stockTicker.py index e6eec87..a40eb37 100644 --- a/stockTicker.py +++ b/stockTicker.py @@ -108,10 +108,10 @@ class StockTicker(): (r, g, b) = pixels[x, y] self.matrix.SetPixel(x + offset_x, y + offset_y, r*self.brightness, g*self.brightness, b*self.brightness) - def scrollImage(self, image, double_buffer, offset_x = 0, offset_y = 0, frame_skip = 10, gif = False): + def scrollImage(self, image, offset_x = 0, offset_y = 0, frame_skip = 10, gif = False, pause_frames = 0): img_width, img_height = image.size kill = False - while offset_x > -img_width: + while offset_x > -(img_width+1): # for animation in gifs if offset_x%frame_skip == 0: @@ -122,27 +122,52 @@ class StockTicker(): #self.setImage(image.convert('RGB'), offset_x = offset_x, offset_y = offset_y) if gif: - double_buffer.SetImage(image, offset_x, offset_y) - else: - double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y) - + self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y) + else: + self.double_buffer.SetImage(image, offset_x, offset_y) + buff = 0 # remove the ppixels behind the image, to stop trailing - double_buffer = self.matrix.SwapOnVSync(double_buffer) + self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer) for y in range(self.matrix.height): - self.matrix.SetPixel(offset_x + img_width , y , 0,0,0) self.matrix.SetPixel(offset_x + img_width +1 , y , 0,0,0) - self.matrix.SetPixel(offset_x + img_width +2 , y , 0,0,0) + self.matrix.SetPixel(offset_x + img_width , y , 0,0,0) + time.sleep(self.delay) kill = self.checkKilled() + + if offset_x == 0: + while pause_frames > 0: + if pause_frames%frame_skip == 0: + self.incrementGIF(image) + + pause_frames -=1 + if gif: + self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y) + + else: + self.double_buffer.SetImage(image, offset_x, offset_y) + + for y in range(self.matrix.height): + self.matrix.SetPixel(offset_x + img_width +1 , y , 0,0,0) + self.matrix.SetPixel(offset_x + img_width , y , 0,0,0) + + + self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer) + + time.sleep(self.delay) + kill = self.checkKilled() + if kill: break + + if kill: break + if kill: break return kill - - def scrollImageY(self, image, double_buffer, direction = 1, offset_x = 0, offset_y = 0, frame_skip = 10, gif = False): + def scrollImageY(self, image, direction = 1, offset_x = 0, offset_y = 0, frame_skip = 10, gif = False): kill = False while offset_y != 0: @@ -154,11 +179,12 @@ class StockTicker(): offset_y += direction if gif: - double_buffer.SetImage(image, offset_x, offset_y) - else: - double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y) + self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y) - double_buffer = self.matrix.SwapOnVSync(double_buffer) + else: + self.double_buffer.SetImage(image, offset_x, offset_y) + + self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer) time.sleep(self.delay) kill = self.checkKilled() @@ -213,7 +239,7 @@ class StockTicker(): pass return kill - def scrollFunctionsAnimated(self, options, animation = 'continuous'): + def scrollFunctionsAnimated(self, options, animation = 'down'): # scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed @@ -222,6 +248,7 @@ class StockTicker(): kill = False i = 0 # keep track of which image we are displaying + self.double_buffer = self.matrix.CreateFrameCanvas() while True: update_process = Process(target = self.updateMultiple, args = ([options[(i+1) % len(options)]],)) @@ -234,10 +261,7 @@ class StockTicker(): else: image = self.openImage('./display_images/user_gif.gif') - img_width, img_height = image.size - double_buffer = self.matrix.CreateFrameCanvas() - offset_x = 0 if animation == 'traditional': @@ -247,11 +271,10 @@ class StockTicker(): elif animation in ['up', 'down']: offset_x = max(0, 128-img_width) - offset_y = 0 #first scroll image in from bottom - frame_skip = 10 #controls how fast gifs run + frame_skip = int((1/15)/self.delay) #controls how fast gifs run self.frame = 0 pause_frames = int(0.5/self.delay) @@ -262,7 +285,7 @@ class StockTicker(): direction = 1 offset_y = -33 - self.scrollImageY(image, double_buffer, direction = direction, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] != 'display_gif') + self.scrollImageY(image, direction = direction, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] == 'display_gif') offset_y = 0 @@ -273,11 +296,11 @@ class StockTicker(): pause_frames -=1 if options[i % len(options)] != 'display_gif': - double_buffer.SetImage(image, offset_x, offset_y) + self.double_buffer.SetImage(image, offset_x, offset_y) else: - double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y) + self.double_buffer.SetImage(image.convert('RGB'), offset_x, offset_y) - double_buffer = self.matrix.SwapOnVSync(double_buffer) + self.double_buffer = self.matrix.SwapOnVSync(self.double_buffer) time.sleep(self.delay) kill = self.checkKilled() @@ -289,14 +312,86 @@ class StockTicker(): if kill: break - kill = self.scrollImage(image, double_buffer, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] != 'display_gif') + kill = self.scrollImage(image, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = options[i % len(options)] == 'display_gif') if kill: break update_process.join() i+=1 + def scrollMultiple(self, animation = 'down'): + # scrolls trhough all functions with animation. Updates functions and remakes images when each function not being dispplayed + + # read lines from csv + images = [] + delays = [] + kinds = [] + + f = open('csv/multiple.csv', 'r') + CSV = csv.reader(f) + next(CSV) + font = ImageFont.load("./fonts/texgyre-27.pil") + + for row in CSV: + + + kind, content, delay = row + delays.append(delay) + kinds.append(kind) + print(kind, content, delay) + if kind == 'text': + images.append(self.textImage(content, font, 255, 255, 0, True, w_buff = 50)) + elif kind == 'image': + images.append(self.openImage(content).convert('RGB')) + elif kind == 'gif': + images.append(self.openImage(content)) + f.close() + + + kill = False + i = 0 # keep track of which image we are displaying + self.double_buffer = self.matrix.CreateFrameCanvas() + while True: + image = images[i%len(images)] + delay = delays[i%len(images)] + kind = kinds[i%len(images)] + + + img_width, img_height = image.size + + offset_x = 0 + if animation == 'traditional': + offset_x = 128 + elif animation == 'continuous': + offset_x = 0 + elif animation in ['up', 'down']: + offset_x = max(0, 128-img_width) + + offset_y = 0 + #first scroll image in from bottom + + frame_skip = int((1/15)/self.delay) #controls how fast gifs run + self.frame = 0 + + pause_frames = int(float(delay)/self.delay) + if animation == 'up': + offset_y = 33 + direction = -1 + elif animation == 'down': + direction = 1 + offset_y = -33 + + self.scrollImageY(image, direction = direction, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = kind=='gif') + offset_y = 0 + + + + kill = self.scrollImage(image, offset_x = offset_x, offset_y = offset_y, frame_skip = frame_skip, gif = kind=='gif', pause_frames = pause_frames) + + if kill: break + i+=1 + def textImage(self, text, font, r = 255, g = 255, b = 255, matrix_height = False, w_buff = 3, h_buff = 3): ''' creates and returns a ppm image containing the text in the supplied font and colour @@ -1846,6 +1941,9 @@ class StockTicker(): userSettings = ['stocks_prof', 'crypto_prof', 'forex_prof', 'today_weather_prof'] self.scrollFunctionsAnimatedProf(userSettings) + + elif msg == '+': + stock_ticker.scrollMultiple() elif msg == 'K': # kill self.resetMatrix() @@ -1855,7 +1953,7 @@ if __name__ == '__main__': with open('log.txt', "w") as log: try: stock_ticker = StockTicker() - + # #stock_ticker.process_msg('b') diff --git a/templates/index.html b/templates/index.html index e092e92..4c720d2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -22,6 +22,7 @@ +