image creation fefactor started

This commit is contained in:
Neythen 2021-09-30 20:17:53 +01:00
parent c16f7eef5b
commit 165ec5a52b
29 changed files with 86 additions and 97 deletions

View File

@ -1 +1 @@
{"feature": "Current Weather", "speed": "medium", "animation": "continuous", "temp": "celsius", "wind_speed": "miles/sec", "colour": "white", "city_colour": "yellow", "title": true, "locations": {"Moscow": [{"main_weather": "Rain", "description": "light rain", "min_temp": 7.65, "max_temp": 10.51}, {"main_weather": "Rain", "description": "light rain", "min_temp": 8.46, "max_temp": 9.36}, {"main_weather": "Rain", "description": "light rain", "min_temp": 7.77, "max_temp": 10.32}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 6.71, "max_temp": 8.53}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 4.13, "max_temp": 9.61}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 5.87, "max_temp": 12.32}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 5.82, "max_temp": 12.78}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 6.06, "max_temp": 13.3}], "London": [{"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 16.43, "max_temp": 21.14}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 14.49, "max_temp": 22.91}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 13.23, "max_temp": 18.43}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 12.03, "max_temp": 17.55}, {"main_weather": "Rain", "description": "light rain", "min_temp": 8.64, "max_temp": 15.93}, {"main_weather": "Rain", "description": "light rain", "min_temp": 11.89, "max_temp": 17.45}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 12.55, "max_temp": 18.84}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 10.94, "max_temp": 15.26}], "Beijing": [{"main_weather": "Rain", "description": "light rain", "min_temp": 18.1, "max_temp": 22.92}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 17.48, "max_temp": 19.87}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 16.77, "max_temp": 25.9}, {"main_weather": "Rain", "description": "light rain", "min_temp": 18.78, "max_temp": 23.9}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 18.28, "max_temp": 28.13}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.59, "max_temp": 21.57}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.99, "max_temp": 20.7}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.22, "max_temp": 26.37}], "Tokyo": [{"main_weather": "Rain", "description": "light rain", "min_temp": 21.23, "max_temp": 24.98}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 20.36, "max_temp": 23.48}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 19.58, "max_temp": 25.58}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 19.32, "max_temp": 25.64}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 19.51, "max_temp": 23.75}, {"main_weather": "Rain", "description": "light rain", "min_temp": 20.69, "max_temp": 23.92}, {"main_weather": "Rain", "description": "light rain", "min_temp": 20.13, "max_temp": 27.1}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 20.75, "max_temp": 25.79}]}, "current_weather": true}
{"feature": "Current Weather", "speed": "medium", "animation": "continuous", "temp": "celsius", "wind_speed": "miles/sec", "colour": "white", "city_colour": "yellow", "title": true, "locations": {"Moscow": [{"main_weather": "Rain", "description": "light rain", "min_temp": 7.65, "max_temp": 10.51}, {"main_weather": "Rain", "description": "light rain", "min_temp": 8.46, "max_temp": 9.36}, {"main_weather": "Rain", "description": "light rain", "min_temp": 7.77, "max_temp": 10.32}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 6.71, "max_temp": 8.53}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 4.13, "max_temp": 9.61}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 5.87, "max_temp": 12.32}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 5.82, "max_temp": 12.78}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 6.06, "max_temp": 13.3}], "London": [{"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 16.43, "max_temp": 21.14}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 14.49, "max_temp": 22.91}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 13.23, "max_temp": 18.43}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 12.03, "max_temp": 17.55}, {"main_weather": "Rain", "description": "light rain", "min_temp": 8.64, "max_temp": 15.93}, {"main_weather": "Rain", "description": "light rain", "min_temp": 11.89, "max_temp": 17.45}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 12.55, "max_temp": 18.84}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 10.94, "max_temp": 15.26}], "Beijing": [{"main_weather": "Rain", "description": "light rain", "min_temp": 18.1, "max_temp": 22.92}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 17.48, "max_temp": 19.87}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 16.77, "max_temp": 25.9}, {"main_weather": "Rain", "description": "light rain", "min_temp": 18.78, "max_temp": 23.9}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 18.28, "max_temp": 28.13}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.59, "max_temp": 21.57}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.99, "max_temp": 20.7}, {"main_weather": "Rain", "description": "light rain", "min_temp": 17.22, "max_temp": 26.37}], "Tokyo": [{"main_weather": "Rain", "description": "light rain", "min_temp": 21.23, "max_temp": 24.98}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 20.36, "max_temp": 23.48}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 19.58, "max_temp": 25.58}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 19.32, "max_temp": 25.64}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 19.51, "max_temp": 23.75}, {"main_weather": "Rain", "description": "light rain", "min_temp": 20.69, "max_temp": 23.92}, {"main_weather": "Rain", "description": "light rain", "min_temp": 20.13, "max_temp": 27.1}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 20.75, "max_temp": 25.79}]}, "current_weather": true}

0
display_images/Crypto Prof.ppm Normal file → Executable file
View File

BIN
display_images/Crypto.ppm Normal file → Executable file

Binary file not shown.

0
display_images/Current Weather.ppm Normal file → Executable file
View File

0
display_images/Custom GIFs.gif Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

0
display_images/Custom Images.ppm Normal file → Executable file
View File

0
display_images/Custom Messages.ppm Normal file → Executable file
View File

0
display_images/Daily Forecast.ppm Normal file → Executable file
View File

0
display_images/Forex Prof.ppm Normal file → Executable file
View File

BIN
display_images/Forex.ppm Normal file → Executable file

Binary file not shown.

BIN
display_images/news.ppm → display_images/News.ppm Executable file → Normal file

Binary file not shown.

0
display_images/Sports (Live Games).ppm Normal file → Executable file
View File

0
display_images/Sports (Past Games).ppm Normal file → Executable file
View File

0
display_images/Sports (Team Stats).ppm Normal file → Executable file
View File

0
display_images/Sports (Upcoming Games).ppm Normal file → Executable file
View File

0
display_images/Stocks Prof.ppm Normal file → Executable file
View File

BIN
display_images/Stocks.ppm Normal file → Executable file

Binary file not shown.

Binary file not shown.

0
display_images/crypto_prof.ppm Normal file → Executable file
View File

Binary file not shown.

0
display_images/forex_prof.ppm Normal file → Executable file
View File

0
display_images/future_games.ppm Normal file → Executable file
View File

0
display_images/live_games.ppm Normal file → Executable file
View File

0
display_images/past_games.ppm Normal file → Executable file
View File

Binary file not shown.

0
display_images/stocks_prof.ppm Normal file → Executable file
View File

0
display_images/today_weather_prof.ppm Normal file → Executable file
View File

View File

@ -9,7 +9,7 @@ pip3 install geopy
sudo apt-get install libopenjp2-7
sudo apt-get install libtiff5
chmod -R ugo+rwx display_images
sudo chmod -R ugo+rwx display_images
cd rpi-rgb-led-matrix
sudo apt-get update && sudo apt-get install python3-dev python3-pillow -y
make build-python PYTHON=$(which python3)

View File

@ -651,24 +651,28 @@ class StockTicker():
def getCryptoImage(self):
title_img = self.openImage('feature_titles/crypto.png')
image_list = [title_img]
image_list.append(self.blank)
start = time.time()
self.readCryptoCSV()
for i, coin in enumerate(self.coins):
f = open('csv/crypto_settings.json', 'r')
all_crypto_settings = json.load(f)
f.close()
info = self.coin_info[coin]
if all_crypto_settings['title']:
title_img = self.openImage('feature_titles/crypto.png')
image_list = [title_img]
image_list.append(self.blank)
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
@ -741,29 +745,37 @@ class StockTicker():
return finalDisplayImage
def getForexImage(self):
title_img = self.openImage('feature_titles/forex.png')
image_list = [title_img]
image_list.append(self.blank)
start = time.time()
base, currency_info = json.load(open('csv/currency.json', 'r'))
currencies = ['AUD', 'CAD', 'CHF', 'EUR', 'GBP', 'JPY', 'NZD']
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/forex.png')
image_list = [title_img]
image_list.append(self.blank)
forex_settings = all_forex_settings['symbols']
for i, currency in enumerate(currencies):
current, yesterday = currency_info[currency]
change = 1/current - 1/yesterday
symbol_bases = list(forex_settings.keys())
for i, sb in enumerate(symbol_bases):
symbol, base = sb.split(',')
current = forex_settings[sb]['current']
change = forex_settings[sb]['24hr_change']
current = 1/current
current = '%.3f' % current
arrow, change = self.getArrow(change)
change = '%.6f' % change
midFrame = self.textToImage(currency + '(' + base + ')', current, change, arrow) #IMAGE THE TEXT
midFrame = self.textToImage(symbol+ '(' + base + ')', current, change, arrow) #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))
@ -839,22 +851,33 @@ class StockTicker():
return finalDisplayImage
def getStockImage(self):
title_img = self.openImage('feature_titles/stocks.png')
image_list = [title_img]
image_list.append(self.blank)
start = time.time()
self.readStocksCSV()
for i, symbol in enumerate(self.symbols):
f = open('csv/stocks_settings.json', 'r')
all_stocks_settings = json.load(f)
f.close()
if all_stocks_settings['title']:
title_img = self.openImage('feature_titles/stocks.png')
image_list = [title_img]
image_list.append(self.blank)
symbols = []
stock_info = {}
stock_info = all_stocks_settings['symbols']
symbols = list(stock_info.keys())
for i, symbol in enumerate(symbols):
info = self.stock_info[symbol]
info = stock_info[symbol]
change = float(info[0])-float(info[1]) #TEXT
change = float(info['current'])-float(info['opening']) #TEXT
ticker = symbol #TEXT
current = '%.2f' % float(info[0]) #TEXT
current = '%.2f' % float(info['current']) #TEXT
arrow, change = self.getArrow(change)
change = '%.2f' % change
@ -937,29 +960,29 @@ class StockTicker():
def getNewsImage(self):
title_img = self.openImage('feature_titles/news.png')
all_settings = json.load(open('csv/news_settings.json', 'r'))
if all_settings['title']:
title_img = self.openImage('feature_titles/news.png')
image_list = [title_img]
headline_font = ImageFont.load("./fonts/6x13.pil")
source_font = ImageFont.load("./fonts/6x13.pil")
image_list = [title_img]
headline_info = all_settings['headlines']
headlines = []
source_date_times = []
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)
source_date_times.append(source + ': ' + date + ' ' + time)
sources.append(source)
f.close()
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("", "'")
@ -973,10 +996,10 @@ class StockTicker():
headline = lst[0]
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_time, source_font, r=255, g=255, b=0, matrix_height = True)
try:
logo_name = sources[i].lower().replace(' ', '-')
logo_name = sources.lower().replace(' ', '-')
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'news_logos')
logo = Image.open(os.path.join(logos_path, logo_name + '.png'))
@ -1640,13 +1663,13 @@ class StockTicker():
def getDailyWeatherImage(self):
f = open( "csv/weather_location.txt", 'r' )
line = next(f)
locations = line.split(',')
f.close()
all_settings = json.load(open('csv/daily_weather.json', 'r'))
title_img = self.openImage('feature_titles/forecast.png')
imgs = [title_img, self.blank]
if all_settings['title']:
title_img = self.openImage('feature_titles/forecast.png')
imgs = [title_img, self.blank]
else:
imgs = []
current_weathers = json.load(open('csv/current_weather.json', 'r'))
@ -1792,43 +1815,7 @@ class StockTicker():
return self.stitchImage(imgs)
#Retrieve symbols and stock info from the csv file
def readStocksCSV(self):
self.symbols = []
self.stock_info = {}
f = open('csv/tickers.csv', 'r')
CSV = csv.reader(f)
next(CSV)
for row in CSV:
try:
symbol, current_price, opening_price = row
self.symbols.append(symbol)
self.stock_info[symbol] = [current_price, opening_price]
except:
pass # we dont want to include incomplete information
f.close()
def readCryptoCSV(self):
self.coins = []
self.coin_info = {}
f = open('csv/crypto.csv', 'r')
CSV = csv.reader(f)
next(CSV)
for row in CSV:
try:
symbol, coin, base, current_price, day_change = row
self.coins.append(coin)
self.coin_info[coin] = [symbol, base, current_price, day_change]
except:
pass
f.close()
def readSportsCSV(self, league):
team_info = {}
@ -2139,6 +2126,8 @@ if __name__ == '__main__':
stock_ticker = StockTicker()
start_image = Image.open('./logos/startup_logo.png')
stock_ticker.updateMultiple(['News'])
stock_ticker.setImage(start_image)
time.sleep(1)
stock_ticker.resetMatrix()