diff --git a/csv/display_settings.json b/csv/display_settings.json index 325939f..1ed1427 100755 --- a/csv/display_settings.json +++ b/csv/display_settings.json @@ -1 +1 @@ -["Stocks", "Crypto", "Forex", "Current Weather"] \ No newline at end of file +["Custom Images"] \ No newline at end of file diff --git a/csv/image_settings.json b/csv/image_settings.json index a1250c3..9944c1e 100644 --- a/csv/image_settings.json +++ b/csv/image_settings.json @@ -1 +1 @@ -{"speed": "medium", "animation": "continuous", "title": true, "pause": "", "images": ["image.png"]} +{"speed": "medium", "animation": "continuous", "title": true, "pause": "", "images": ["ZM.png", "WORK.png"]} \ No newline at end of file diff --git a/display_images/Crypto Prof.ppm b/display_images/Crypto Prof.ppm index 179da1c..4b65ac3 100755 Binary files a/display_images/Crypto Prof.ppm and b/display_images/Crypto Prof.ppm differ diff --git a/display_images/forex_prof.ppm b/display_images/Current Weather Prof.ppm old mode 100755 new mode 100644 similarity index 51% rename from display_images/forex_prof.ppm rename to display_images/Current Weather Prof.ppm index 27248b7..4b68bac Binary files a/display_images/forex_prof.ppm and b/display_images/Current Weather Prof.ppm differ diff --git a/display_images/Current Weather.ppm b/display_images/Current Weather.ppm index 864d219..4dacfbc 100755 Binary files a/display_images/Current Weather.ppm and b/display_images/Current Weather.ppm differ diff --git a/display_images/Forex Prof.ppm b/display_images/Forex Prof.ppm index f0f32af..54f724b 100755 Binary files a/display_images/Forex Prof.ppm and b/display_images/Forex Prof.ppm differ diff --git a/display_images/News Prof.ppm b/display_images/News Prof.ppm new file mode 100644 index 0000000..ead18f1 Binary files /dev/null and b/display_images/News Prof.ppm differ diff --git a/display_images/Stocks Prof.ppm b/display_images/Stocks Prof.ppm index 2999c0a..f216f65 100755 Binary files a/display_images/Stocks Prof.ppm and b/display_images/Stocks Prof.ppm differ diff --git a/display_images/crypto_prof.ppm b/display_images/crypto_prof.ppm deleted file mode 100755 index da09d89..0000000 Binary files a/display_images/crypto_prof.ppm and /dev/null differ diff --git a/display_images/stocks_prof.ppm b/display_images/stocks_prof.ppm deleted file mode 100755 index b434a1a..0000000 Binary files a/display_images/stocks_prof.ppm and /dev/null differ diff --git a/log.txt b/log.txt index e17fcc9..3720a22 100755 --- a/log.txt +++ b/log.txt @@ -1,9 +1,17 @@ -'StockTicker' object has no attribute 'readStocksCSV'. file: stockTicker.py. line: 2186. type: +[Errno 2] No such file or directory: '/home/pi/Desktop/stock_ticker/ZM.png'. file: stockTicker.py. line: 2230. type: Traceback (most recent call last): - File "stockTicker.py", line 2186, in - stock_ticker.updateMultiple(['Stocks Prof']) + File "stockTicker.py", line 2230, in + stock_ticker.process_msg(msg) + File "stockTicker.py", line 2194, in process_msg + self.scrollFunctionsAnimated(userSettings, animation = 'down') + File "stockTicker.py", line 309, in scrollFunctionsAnimated + self.updateMultiple([options[0]]) File "stockTicker.py", line 276, in updateMultiple img = self.functions[option]() - File "stockTicker.py", line 927, in getStockProfessional - self.readStocksCSV() -AttributeError: 'StockTicker' object has no attribute 'readStocksCSV' + File "stockTicker.py", line 1953, in getUserImage + image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), image)) + File "stockTicker.py", line 76, in openImage + image = Image.open(image_file) + File "/usr/lib/python3/dist-packages/PIL/Image.py", line 2634, in open + fp = builtins.open(filename, "rb") +FileNotFoundError: [Errno 2] No such file or directory: '/home/pi/Desktop/stock_ticker/ZM.png' diff --git a/static/app.js b/static/app.js index fe27ba7..d633055 100644 --- a/static/app.js +++ b/static/app.js @@ -491,6 +491,7 @@ allFeaturesFileAddBtn.map((value, index) => { value.addEventListener("click", () => { var tag = document.createElement("li"); tag.innerHTML = allFeaturesFile[index].files[0].name; + allFeatures[index].appendChild(tag); changeVarValue(); addEventOnFeaturesList(); diff --git a/stockTicker.py b/stockTicker.py index 1df33d3..5a8a9da 100644 --- a/stockTicker.py +++ b/stockTicker.py @@ -702,23 +702,35 @@ class StockTicker(): def getCryptoProfessional(self): - title_img = self.openImage('feature_titles/small_feature_titles/crypto.png') + self.blank = Image.new('RGB', (0, 16)) - image_list = [title_img, Image.new('RGB', (5, 16))] - start = time.time() - self.readCryptoCSV() + f = open('csv/crypto_settings.json', 'r') + all_crypto_settings = json.load(f) + f.close() - for i, coin in enumerate(self.coins): + if all_crypto_settings['title']: + title_img = self.openImage('feature_titles/small_feature_titles/crypto.png') + image_list = [title_img] + image_list.append(self.blank) + else: + image_list = [] - info = self.coin_info[coin] + + + coin_info = all_crypto_settings['symbols'] + coin_bases = list(coin_info.keys()) + + + + + for i, cb in enumerate(coin_bases): + + ticker, base = cb.split(',') + current = coin_info[cb]["current"] + change = coin_info[cb]["24hr_change"] - change = float(info[3]) #TEXT - ticker = info[0] #TEXT - current = float(info[2]) #TEXT - base = info[1].upper() - - if self.points: + if all_crypto_settings["point"]: # convert percent to points change = change/100 * current @@ -802,41 +814,42 @@ class StockTicker(): def getForexProfessional(self): + self.blank = Image.new('RGB', (0, 16)) f = open('csv/forex_settings.json', 'r') all_forex_settings = json.load(f) f.close() if all_forex_settings['title']: title_img = self.openImage('feature_titles/small_feature_titles/forex.png') - self.blank = Image.new('RGB', (0, 16)) - image_list = [title_img, Image.new('RGB', (5, 16))] + image_list = [title_img] + image_list.append(self.blank) else: image_list = [] + forex_settings = all_forex_settings['symbols'] - base, currency_info = json.load(open('csv/currency.json', 'r')) - currencies = ['AUD', 'CAD', 'CHF', 'EUR', 'GBP', 'JPY', 'NZD'] + + symbol_bases = list(forex_settings.keys()) - for i, currency in enumerate(currencies): + for i, sb in enumerate(symbol_bases): + symbol, base = sb.split(',') + + current = forex_settings[sb]['current'] + change = forex_settings[sb]['24hr_change'] - current, yesterday = currency_info[currency] - - change = 1/current - 1/yesterday - - current = 1/current current = '%.3f' % current arrow, change = self.getArrow(change, professional = True) change = '%.6f' % change - midFrame = self.textToImageProf(currency + '(' + base + ')', current, change, arrow, font = ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT + midFrame = self.textToImageProf(symbol + '(' + base + ')', current, change, arrow, font = ImageFont.load("./fonts/6x10.pil")) #IMAGE THE TEXT try: logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'currencies') - logo = Image.open(os.path.join(logos_path, currency.lower() + '.png')) + logo = Image.open(os.path.join(logos_path, symbol.lower() + '.png')) bse = Image.open(os.path.join(logos_path, base.lower() + '.png')) new_im = Image.new('RGB', (32, 32)) @@ -878,8 +891,7 @@ class StockTicker(): image_list = [] - symbols = [] - stock_info = {} + stock_info = all_stocks_settings['symbols'] symbols = list(stock_info.keys()) @@ -920,6 +932,7 @@ class StockTicker(): return finalDisplayImage def getStockProfessional(self): + self.blank = Image.new('RGB', (0, 16)) f = open('csv/stocks_settings.json', 'r') all_stocks_settings = json.load(f) @@ -932,10 +945,11 @@ class StockTicker(): else: image_list = [] - self.readStocksCSV() - - self.blank = Image.new('RGB', (0, 16)) - for i, symbol in enumerate(self.symbols): + + stock_info = all_stocks_settings['symbols'] + symbols = list(stock_info.keys()) + + for i, symbol in enumerate(symbols): info = stock_info[symbol] @@ -1052,28 +1066,30 @@ class StockTicker(): def getNewsProfessional(self): - headline_font = ImageFont.load("./fonts/6x10.pil") - source_font = ImageFont.load("./fonts/6x10.pil") + all_settings = json.load(open('csv/news_settings.json', 'r')) - title_img = self.openImage('feature_titles/small_feature_titles/news.png') - image_list = [title_img, Image.new('RGB', (5, 16))] - - headlines = [] - sources = [] - - f = open('csv/news.csv', 'r') - CSV = csv.reader(f) - next(CSV) - for row in CSV: - headline, source, date, time = row - headlines.append(headline) - sources.append(source) + if all_settings['title']: + title_img = self.openImage('feature_titles/small_feature_titles/news.png') + image_list = [title_img] - f.close() + headline_font = ImageFont.load("./fonts/6x13.pil") + source_font = ImageFont.load("./fonts/6x13.pil") + + headline_info = all_settings['headlines'] + + headlines = [] + source_date_times = [] + sources = [] blank = Image.new('RGB', (0, 16)) - for i, headline in enumerate(headlines): + + for i, hi in enumerate(headline_info): + headline, source, date_time = hi + date, time = date_time.split('T') + time = time[:-1] + source_date_time = source + ': ' + date + ' ' + time + headline = headline.replace("^", ",") headline = headline.replace("’", "'") headline = headline.replace("‘", "'") @@ -1088,7 +1104,7 @@ class StockTicker(): headline = lst[0] headline_img = self.textImage(headline, headline_font, matrix_height = True) - source_img = self.textImage(sources[i] + ':', source_font, r=255, g=255, b=0, matrix_height = True) + source_img = self.textImage(source_date_time+ ':', source_font, r=255, g=255, b=0, matrix_height = True) try: @@ -1453,27 +1469,32 @@ class StockTicker(): return self.stitchImage(imgs) def getTodayWeatherProfessional(self): - f = open( "csv/weather_location.txt", 'r' ) - line = next(f) - locations = line.split(',') - f.close() + all_settings = json.load(open('csv/current_weather.json', 'r')) - title_img = self.openImage('feature_titles/small_feature_titles/weather.png') - image_list = [title_img, Image.new('RGB', (3, 16))] + if all_settings['title']: + title_img = self.openImage('feature_titles/small_feature_titles/weather.png') + image_list = [title_img, Image.new('RGB', (3, 16))] + else: + image_list = [] + + + + current_weathers = all_settings['locations'] + locations = list(current_weathers.keys()) - current_weathers = json.load(open('csv/current_weather.json', 'r')) weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] months =['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] month = months[int(datetime.now().strftime('%m'))-1] date = str(int(datetime.now().strftime('%d'))) weekday = weekdays[datetime.today().weekday()] - + for i, location in enumerate(locations): + img = Image.new('RGB', (1000, 32)) - current_weather = current_weathers[i] + current_weather = current_weathers[location] small_font = ImageFont.load("./fonts/4x6.pil") font = ImageFont.load("./fonts/6x10.pil") large_font = ImageFont.load("./fonts/10x20.pil") @@ -1555,9 +1576,9 @@ class StockTicker(): - img = img.crop((0,0,x_offset +image.size[0] ,16)) + img = img.crop((0,0,x_offset +image.size[0] ,16)) - image_list.append(img) + image_list.append(img) return self.stitchImage(image_list) def getDailyWeatherImageAlt(self): @@ -1923,21 +1944,22 @@ class StockTicker(): f = open('csv/image_settings.json', 'r') all_settings = json.load(f) f.close() - - - image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/user_image.ppm')) - if all_settings['title']: - imgs = [title_img, image] + imgs = [title_img] else: - imgs = [image] + imgs = [] + + for image in all_settings['images']: + image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), image)) + + return self.stitchImage(imgs) def getUserGIF(self): title_img = self.openImage('feature_titles/gifs.png') - gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/user_gif.gif')) + gif = Image.open(os.path.join(os.path.dirname(os.path.abspath(__file__)), all_settings['images'][0])) f = open('csv/GIF_settings.json', 'r') all_settings = json.load(f) @@ -2191,7 +2213,7 @@ if __name__ == '__main__': start_image = Image.open('./logos/startup_logo.png') - stock_ticker.updateMultiple(['Stocks Prof', 'Crypto Prof', 'Forex Prof']) + stock_ticker.setImage(start_image) time.sleep(1) stock_ticker.resetMatrix()