non prof image generation finished

This commit is contained in:
Neythen
2021-10-04 21:39:22 +01:00
parent 165ec5a52b
commit 65dfcdc321
44 changed files with 282 additions and 206 deletions
+13 -9
View File
@@ -327,7 +327,7 @@ def updateWeather():
all_daily_settings = json.load(f) all_daily_settings = json.load(f)
f.close() f.close()
f = open('csv/daily_weather.json', 'r') f = open('csv/current_weather.json', 'r')
all_current_settings = json.load(f) all_current_settings = json.load(f)
f.close() f.close()
@@ -370,8 +370,8 @@ def updateWeather():
current_weather['rain_chance'] = r.json()['hourly'][0]['pop'] current_weather['rain_chance'] = r.json()['hourly'][0]['pop']
if location in current_locations:
current_weathers[location] = current_weather current_weathers[location] = current_weather
daily_weather = [] daily_weather = []
daily = r.json()['daily'] daily = r.json()['daily']
@@ -385,8 +385,8 @@ def updateWeather():
daily_weather.append(dct) daily_weather.append(dct)
if location in daily_locations:
daily_weathers[location] = daily_weather daily_weathers[location] = daily_weather
@@ -546,7 +546,11 @@ def checkStocks(last_update, update_frequency):
closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0).replace(tzinfo=None) closing = NY_time.replace(hour=16, minute=0, second=0, microsecond=0).replace(tzinfo=None)
symbols, stock_info = readJSON('csv/stocks_settings.json', max_stocks) f = open('csv/stocks_settings.json', 'r')
all_stocks_settings = json.load(f)
f.close()
stock_info = all_stocks_settings['symbols']
symbols = list(stock_info.keys())
updated = False updated = False
@@ -589,8 +593,7 @@ if __name__ == '__main__':
newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9') newsapi = NewsApiClient(api_key='cf08652bd17647b89aaf469a1a8198a9')
updateNews()
sys.exit()
update_frequencies = {'stocks':2, 'crypto':10, 'news':120, 'weather': 120, 'sports': 120} #minutes update_frequencies = {'stocks':2, 'crypto':10, 'news':120, 'weather': 120, 'sports': 120} #minutes
@@ -610,7 +613,8 @@ if __name__ == '__main__':
#f.close() #f.close()
updateWeather()
sys.exit()
try: try:
f = open('csv/last_updates.json', 'r') f = open('csv/last_updates.json', 'r')
last_updates = json.load(f) last_updates = json.load(f)
+1 -1
View File
@@ -1 +1 @@
{"feature": "Stocks", "speed": "medium", "animation": "continuous", "percent": false, "point": true, "logos": true, "chart": false, "title": true, "symbols": {"NEO,USD": {"current": 38.91, "24hr_change": -10.214531272448745}, "BTC,USD": {"current": 42257, "24hr_change": -6.370431167988443}, "ETH,BTC": {"current": 0.06787408, "24hr_change": -7.725740924537157}, "ADA,GBP": {"current": 1.69, "24hr_change": -0.5989543849163771}}} {"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}}}
+1 -1
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", "temp": 9.49, "min_temp": 7.65, "max_temp": 10.51, "feels_like": 7.58, "humidity": 84, "clouds": 100, "wind_speed": 3.59, "wind_direction": 183, "visibility": 10000, "uv": 0.78, "rain_chance": 0.2}, "London": {"main_weather": "Clouds", "description": "overcast clouds", "temp": 16.83, "min_temp": 16.43, "max_temp": 21.14, "feels_like": 16.97, "humidity": 92, "clouds": 90, "wind_speed": 1.54, "wind_direction": 0, "visibility": 10000, "uv": 1.35, "rain_chance": 0}, "Beijing": {"main_weather": "Clouds", "description": "overcast clouds", "temp": 22.72, "min_temp": 18.1, "max_temp": 22.92, "feels_like": 22.69, "humidity": 63, "clouds": 99, "wind_speed": 2.06, "wind_direction": 185, "visibility": 10000, "uv": 0.28, "rain_chance": 0.06}, "Tokyo": {"main_weather": "Clouds", "description": "scattered clouds", "temp": 22, "min_temp": 21.23, "max_temp": 24.98, "feels_like": 22.16, "humidity": 73, "clouds": 40, "wind_speed": 1.34, "wind_direction": 52, "visibility": 10000, "uv": 0, "rain_chance": 0.36}}, "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": "Clouds", "description": "few clouds", "temp": 4.6, "min_temp": 4.6, "max_temp": 11.07, "feels_like": 2.79, "humidity": 73, "clouds": 16, "wind_speed": 2.11, "wind_direction": 120, "visibility": 10000, "uv": 0, "rain_chance": 0}, "Beijing": {"main_weather": "Clouds", "description": "overcast clouds", "temp": 11.63, "min_temp": 11.63, "max_temp": 14.76, "feels_like": 11.28, "humidity": 93, "clouds": 100, "wind_speed": 1.1, "wind_direction": 9, "visibility": 10000, "uv": 0, "rain_chance": 0.84}, "Tokyo": {"main_weather": "Clouds", "description": "few clouds", "temp": 21.42, "min_temp": 21.42, "max_temp": 27.62, "feels_like": 21.73, "humidity": 81, "clouds": 20, "wind_speed": 0.45, "wind_direction": 291, "visibility": 10000, "uv": 0, "rain_chance": 0}, "London": {"main_weather": "Clouds", "description": "overcast clouds", "temp": 12.23, "min_temp": 11.77, "max_temp": 16.42, "feels_like": 11.91, "humidity": 92, "clouds": 91, "wind_speed": 4.01, "wind_direction": 181, "visibility": 10000, "uv": 0, "rain_chance": 0}}, "current_weather": true}
+1 -1
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": "Clouds", "description": "broken clouds", "min_temp": 4.6, "max_temp": 11.07}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 4.88, "max_temp": 11.53}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 4.11, "max_temp": 11.44}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 3.34, "max_temp": 10.75}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 3.99, "max_temp": 11.32}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 4.57, "max_temp": 11.12}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 3.94, "max_temp": 9.68}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 5.99, "max_temp": 10.77}], "Beijing": [{"main_weather": "Rain", "description": "light rain", "min_temp": 11.63, "max_temp": 14.76}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 10.22, "max_temp": 12.33}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 10.29, "max_temp": 17.61}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 11.53, "max_temp": 19.55}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 13.15, "max_temp": 19.6}, {"main_weather": "Rain", "description": "moderate rain", "min_temp": 14.29, "max_temp": 19.8}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 13.08, "max_temp": 18.87}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 11.42, "max_temp": 19.6}], "Tokyo": [{"main_weather": "Clear", "description": "clear sky", "min_temp": 21.42, "max_temp": 27.62}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 21.12, "max_temp": 26.36}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 20.3, "max_temp": 22.81}, {"main_weather": "Rain", "description": "light rain", "min_temp": 21.31, "max_temp": 26.99}, {"main_weather": "Rain", "description": "light rain", "min_temp": 20.53, "max_temp": 23.98}, {"main_weather": "Rain", "description": "light rain", "min_temp": 19.15, "max_temp": 24.43}, {"main_weather": "Clouds", "description": "few clouds", "min_temp": 21.26, "max_temp": 26.41}, {"main_weather": "Rain", "description": "light rain", "min_temp": 22.4, "max_temp": 26.43}], "London": [{"main_weather": "Rain", "description": "light rain", "min_temp": 11.77, "max_temp": 16.42}, {"main_weather": "Rain", "description": "heavy intensity rain", "min_temp": 10.89, "max_temp": 13.15}, {"main_weather": "Clear", "description": "clear sky", "min_temp": 9.54, "max_temp": 15.37}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 10.64, "max_temp": 17.51}, {"main_weather": "Clouds", "description": "overcast clouds", "min_temp": 13.65, "max_temp": 17.56}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 14.4, "max_temp": 18.88}, {"main_weather": "Clouds", "description": "scattered clouds", "min_temp": 12.83, "max_temp": 18.66}, {"main_weather": "Clouds", "description": "broken clouds", "min_temp": 12.03, "max_temp": 19.24}]}, "current_weather": true}
-1
View File
@@ -1 +0,0 @@
{"stocks": "19/09/2021 12:09:24", "crypto": "19/09/2021 12:09:26", "news": "19/09/2021 12:09:28", "weather": "19/09/2021 12:09:26", "forex": "19/09/2021 18:09:31", "sports": "19/09/2021 12:09:29"}
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1 +1 @@
{"feature": "Stocks", "speed": "medium", "animation": "continuous", "percent": true, "point": false, "logos": true, "chart": false, "title": true, "symbols": {"MSFT": {"current": 299.35, "opening": 298.21}, "GOOG": {"current": 2854.185, "opening": 2821.99}}} {"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}}}
File diff suppressed because one or more lines are too long
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.
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
'StockTicker' object has no attribute 'readStocksCSV'. file: stockTicker.py. line: 2186. type: <class 'AttributeError'>
Traceback (most recent call last):
File "stockTicker.py", line 2186, in <module>
stock_ticker.updateMultiple(['Stocks Prof'])
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'

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

+253 -189
View File
@@ -661,6 +661,8 @@ class StockTicker():
title_img = self.openImage('feature_titles/crypto.png') 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)
else:
image_list = []
@@ -754,6 +756,8 @@ class StockTicker():
title_img = self.openImage('feature_titles/forex.png') title_img = self.openImage('feature_titles/forex.png')
image_list = [title_img] image_list = [title_img]
image_list.append(self.blank) image_list.append(self.blank)
else:
image_list = []
forex_settings = all_forex_settings['symbols'] forex_settings = all_forex_settings['symbols']
@@ -798,10 +802,18 @@ class StockTicker():
def getForexProfessional(self): def getForexProfessional(self):
title_img = self.openImage('feature_titles/small_feature_titles/forex.png') f = open('csv/forex_settings.json', 'r')
self.blank = Image.new('RGB', (0, 16)) all_forex_settings = json.load(f)
image_list = [title_img, Image.new('RGB', (5, 16))] 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))]
else:
image_list = []
base, currency_info = json.load(open('csv/currency.json', 'r')) base, currency_info = json.load(open('csv/currency.json', 'r'))
currencies = ['AUD', 'CAD', 'CHF', 'EUR', 'GBP', 'JPY', 'NZD'] currencies = ['AUD', 'CAD', 'CHF', 'EUR', 'GBP', 'JPY', 'NZD']
@@ -862,6 +874,8 @@ class StockTicker():
title_img = self.openImage('feature_titles/stocks.png') title_img = self.openImage('feature_titles/stocks.png')
image_list = [title_img] image_list = [title_img]
image_list.append(self.blank) image_list.append(self.blank)
else:
image_list = []
symbols = [] symbols = []
@@ -906,20 +920,30 @@ class StockTicker():
return finalDisplayImage return finalDisplayImage
def getStockProfessional(self): def getStockProfessional(self):
title_img = self.openImage('feature_titles/small_feature_titles/stocks.png')
image_list = [title_img, Image.new('RGB', (5, 16))]
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/small_feature_titles/stocks.png')
image_list = [title_img, Image.new('RGB', (5, 16))]
image_list.append(self.blank)
else:
image_list = []
self.readStocksCSV() self.readStocksCSV()
self.blank = Image.new('RGB', (0, 16)) self.blank = Image.new('RGB', (0, 16))
for i, symbol in enumerate(self.symbols): for i, symbol in enumerate(self.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 ticker = symbol #TEXT
current = '%.2f' % float(info[0]) #TEXT current = '%.2f' % float(info['current']) #TEXT
arrow, change = self.getArrow(change, professional=True) arrow, change = self.getArrow(change, professional=True)
change = '%.2f' % change change = '%.2f' % change
@@ -1078,10 +1102,7 @@ class StockTicker():
logos_path = os.path.join(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'logos'), 'news_logos') 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')) logo = Image.open(os.path.join(logos_path, logo_name + '.png'))
width, height = logo.size width, height = logo.size
logo = logo.resize((int(width/2), int(height/2))) logo = logo.resize((int(width/2), int(height/2)))
@@ -1103,134 +1124,144 @@ class StockTicker():
def getLeagueImage(self, league=False, time = 'past'): def getLeagueImage(self, league=False, time = 'past'):
if not league: if time in ['past', 'live']:
f = open( "csv/league.txt", 'r' ) filepath = 'csv/{}_games.json'.format(time)
league = f.read().replace('\n', '')
f.close()
else:
filepath = 'csv/upcoming_games.json'
all_settings = json.load(open(filepath, 'r'))
title_img = self.openImage('feature_titles/sports_'+ time + '.png') title_img = self.openImage('feature_titles/sports_'+ time + '.png')
if all_settings['title']:
img = Image.new('RGB', (10000, 32)) title_img = self.openImage('feature_titles/sports_{}.png'.format(time))
league_info = json.load(open('csv/sports/{}/{}_games.json'.format(league, time), 'r')) imgs = [title_img, self.blank]
else:
imgs = []
small_font = ImageFont.load("./fonts/5x7.pil")
med_font = ImageFont.load("./fonts/7x14B.pil")
large_font = ImageFont.load("./fonts/9x18B.pil")
sports_info = self.readSportsCSV(league)
buff_size = 25
x_offset = 0
for match in league_info[-15:]:
home_team = match['home_team']
away_team = match['away_team']
home_score = match['home_score']
away_score = match['away_score']
date = match['date'].replace('-', '.')
#rond = match['round']
try: leagues_info = all_settings['leagues']
leagues = list(leagues_info.keys())
for league in leagues:
img = Image.new('RGB', (10000, 32))
league_info = json.load(open('csv/sports/{}/{}_games.json'.format(league, time), 'r'))
small_font = ImageFont.load("./fonts/5x7.pil")
med_font = ImageFont.load("./fonts/7x14B.pil")
large_font = ImageFont.load("./fonts/9x18B.pil")
sports_info = self.readSportsCSV(league)
buff_size = 25
x_offset = 0
for match in league_info[-15:]:
home_team = match['home_team']
away_team = match['away_team']
home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[home_team]['logo'])) home_score = match['home_score']
away_score = match['away_score']
except Exception as e: date = match['date'].replace('-', '.')
home_logo = self.textImage(home_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
#rond = match['round']
try:
try: home_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[home_team]['logo']))
away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[away_team]['logo'])) except Exception as e:
home_logo = self.textImage(home_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
except Exception as e:
away_logo = self.textImage(away_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
try:
away_logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[away_team]['logo']))
except Exception as e:
away_logo = self.textImage(away_team.replace(' ', '\n'), small_font, r = 255, g = 255, b = 255)
date_timage = self.textImage(date, small_font, r = 255, g = 255, b = 255) date_timage = self.textImage(date, small_font, r = 255, g = 255, b = 255)
img.paste(home_logo, (x_offset,0))
x_offset += home_logo.size[0] + 2
if time == 'future':
img.paste(date_timage, (x_offset+5, 0))
h_colour = mcolors.to_rgb(sports_info[home_team]['colour'].replace(' ', '')) img.paste(home_logo, (x_offset,0))
a_colour = mcolors.to_rgb(sports_info[away_team]['colour'].replace(' ', ''))
x_offset += home_logo.size[0] + 2
hc_timage = self.textImage(sports_info[home_team]['code'], med_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255)) if time == 'future':
ac_timage = self.textImage(sports_info[away_team]['code'], med_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255)) img.paste(date_timage, (x_offset+5, 0))
vs_timage = self.textImage('vs', med_font, r = 255, g = 255, b = 255, h_buff = 5)
h_colour = mcolors.to_rgb(sports_info[home_team]['colour'].replace(' ', ''))
img.paste(hc_timage, (x_offset, 9)) a_colour = mcolors.to_rgb(sports_info[away_team]['colour'].replace(' ', ''))
img.paste(vs_timage, (x_offset + hc_timage.size[0], 9))
img.paste(ac_timage, (x_offset + hc_timage.size[0] + vs_timage.size[0], 9))
x_offset += max( date_timage.size[0], hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]) hc_timage = self.textImage(sports_info[home_team]['code'], med_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
else: ac_timage = self.textImage(sports_info[away_team]['code'], med_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
vs_timage = self.textImage('vs', med_font, r = 255, g = 255, b = 255, h_buff = 5)
score_image = self.textImage(home_score + '-' + away_score, large_font, h_buff = 5, r = 255, g = 255, b = 255)
img.paste(hc_timage, (x_offset, 9))
#vs_timage = self.textImage(sports_info[home_team]['code'] + 'vs' + sports_info[away_team]['code'], small_font, r = 255, g = 255, b = 255) img.paste(vs_timage, (x_offset + hc_timage.size[0], 9))
img.paste(ac_timage, (x_offset + hc_timage.size[0] + vs_timage.size[0], 9))
h_colour = mcolors.to_rgb(sports_info[home_team]['colour'].replace(' ', '')) x_offset += max( date_timage.size[0], hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0])
a_colour = mcolors.to_rgb(sports_info[away_team]['colour'].replace(' ', ''))
hc_timage = self.textImage(sports_info[home_team]['code'], small_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
ac_timage = self.textImage(sports_info[away_team]['code'], small_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
vs_timage = self.textImage('vs', small_font, r = 255, g = 255, b = 255)
if date_timage.size[0] > score_image.size[0]:
img.paste(date_timage, (x_offset+2, 0))
img.paste(hc_timage, (x_offset+6, 9))
img.paste(vs_timage, (x_offset+5 + hc_timage.size[0], 9))
img.paste(ac_timage, (x_offset+6 + hc_timage.size[0] + vs_timage.size[0], 9))
img.paste(score_image, (x_offset + 2 + int((date_timage.size[0] - score_image.size[0])/2), 15))
else: else:
img.paste(date_timage, (x_offset+1+int((score_image.size[0] - date_timage.size[0] )/2), 0)) score_image = self.textImage(home_score + '-' + away_score, large_font, h_buff = 5, r = 255, g = 255, b = 255)
vs_size = hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]
img.paste(hc_timage, (x_offset + 1 + int((score_image.size[0] - vs_size)/2), 9))
img.paste(vs_timage, (x_offset + int((score_image.size[0] - vs_size)/2) + hc_timage.size[0], 9))
img.paste(ac_timage, (x_offset+1 + int((score_image.size[0] - vs_size)/2) + hc_timage.size[0] + vs_timage.size[0], 9))
img.paste(score_image, (x_offset+1, 15)) #vs_timage = self.textImage(sports_info[home_team]['code'] + 'vs' + sports_info[away_team]['code'], small_font, r = 255, g = 255, b = 255)
h_colour = mcolors.to_rgb(sports_info[home_team]['colour'].replace(' ', ''))
a_colour = mcolors.to_rgb(sports_info[away_team]['colour'].replace(' ', ''))
hc_timage = self.textImage(sports_info[home_team]['code'], small_font, r = int(h_colour[0]*255), g = int(h_colour[1]*255), b = int(h_colour[2]*255))
ac_timage = self.textImage(sports_info[away_team]['code'], small_font, r = int(a_colour[0]*255), g = int(a_colour[1]*255), b = int(a_colour[2]*255))
vs_timage = self.textImage('vs', small_font, r = 255, g = 255, b = 255)
if date_timage.size[0] > score_image.size[0]:
img.paste(date_timage, (x_offset+2, 0))
img.paste(hc_timage, (x_offset+6, 9))
img.paste(vs_timage, (x_offset+5 + hc_timage.size[0], 9))
img.paste(ac_timage, (x_offset+6 + hc_timage.size[0] + vs_timage.size[0], 9))
img.paste(score_image, (x_offset + 2 + int((date_timage.size[0] - score_image.size[0])/2), 15))
else:
img.paste(date_timage, (x_offset+1+int((score_image.size[0] - date_timage.size[0] )/2), 0))
vs_size = hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]
img.paste(hc_timage, (x_offset + 1 + int((score_image.size[0] - vs_size)/2), 9))
img.paste(vs_timage, (x_offset + int((score_image.size[0] - vs_size)/2) + hc_timage.size[0], 9))
img.paste(ac_timage, (x_offset+1 + int((score_image.size[0] - vs_size)/2) + hc_timage.size[0] + vs_timage.size[0], 9))
img.paste(score_image, (x_offset+1, 15))
x_offset += max( date_timage.size[0]+4, hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]+4, 2 + int(score_image.size[0]))
#img.paste(vs_timage, (x_offset+4, 9))
x_offset += max( date_timage.size[0]+4, hc_timage.size[0] + vs_timage.size[0] + ac_timage.size[0]+4, 2 + int(score_image.size[0])) #if league == 'NHL':
#
#img.paste(round_timage, (x_offset+ 7, 8))
#x_offset += max(home_timage.size[0], away_timage.size[0], date_timage.size[0], round_timage.size[0], score_image.size[0])
img.paste(away_logo, (x_offset,0))
#img.paste(vs_timage, (x_offset+4, 9)) x_offset += away_logo.size[0]
x_offset += buff_size
#if league == 'NHL': img = img.crop((0,0,x_offset ,32))
#
#img.paste(round_timage, (x_offset+ 7, 8))
#x_offset += max(home_timage.size[0], away_timage.size[0], date_timage.size[0], round_timage.size[0], score_image.size[0])
img.paste(away_logo, (x_offset,0))
x_offset += away_logo.size[0]
x_offset += buff_size
img = img.crop((0,0,x_offset ,32))
@@ -1240,81 +1271,92 @@ class StockTicker():
def getLeagueTableImage(self, league = False): def getLeagueTableImage(self, league = False):
if not league: all_settings = json.load(open('csv/league_tables.json', 'r'))
f = open( "csv/table_league.txt", 'r' )
league = f.read().replace('\n', '')
f.close()
title_img = self.openImage('feature_titles/sports_team_stats.png')
leagues_info = all_settings['leagues']
img = Image.new('RGB', (10000, 32)) leagues = list(leagues_info.keys())
team_info = json.load(open('csv/sports/{}/team_stats.json'.format(league), 'r'))
small_font = ImageFont.load("./fonts/5x7.pil") if all_settings['title']:
med_font = ImageFont.load("./fonts/8x13B.pil") title_img = self.openImage('feature_titles/sports_team_stats.png')
large_font = ImageFont.load("./fonts/10x20.pil") imgs = [title_img, self.blank]
else:
if league =='NHL': # read the NHl info from the csv, prem will need this as well imgs = []
sports_info = self.readSportsCSV(league)
buff_size = 20
x_offset = 0
for team in team_info:
try:
if league == 'NHL':
logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo']))
elif league == 'premier_league':
logo = Image.open('logos/sports/{}/{}.png'.format(league, team['name']))
img.paste(logo, (x_offset, 0))
x_offset += logo.size[0] + 2
except Exception as e:
print('no logo for:', team['name'])
for league in leagues:
name_timage = self.textImage(team['name'], med_font, r = 255, g = 255, b = 0)
wins_timage = self.textImage('Wins:' + team['wins'], small_font, r = 0, g = 255, b = 0)
loss_timage = self.textImage('Losses:' + team['loss'], small_font, r = 255, g = 0, b = 0)
draw_timage = self.textImage('Draws:' + team['draw'], small_font, r = 0, g = 0, b = 255)
points_timage = self.textImage('Points:' + team['points'], small_font, r = 255, g = 255, b = 255)
standing_timage = self.textImage('Standing:' + team['standing'], small_font, r = 255, g = 255, b = 255)
img = Image.new('RGB', (10000, 32))
team_info = leagues_info[league]
small_font = ImageFont.load("./fonts/5x7.pil")
med_font = ImageFont.load("./fonts/8x13B.pil")
large_font = ImageFont.load("./fonts/10x20.pil")
#if league =='NHL': # read the NHl info from the csv, prem will need this as well
sports_info = self.readSportsCSV(league) # gets colour and symbol info etc from csv
buff_size = 20
x_offset = 0
for team in team_info:
try:
logo = Image.open('logos/sports/{}/{}'.format(league, sports_info[team['name']]['logo']))
img.paste(name_timage, (x_offset, -1)) img.paste(logo, (x_offset, 0))
img.paste(wins_timage, (x_offset, 12)) x_offset += logo.size[0] + 2
img.paste(loss_timage, (x_offset, 19)) except Exception as e:
img.paste(draw_timage, (x_offset, 26)) print('no logo for:', team['name'])
x_offset += max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0])
img.paste(points_timage, (x_offset, 14)) name_timage = self.textImage(team['name'], med_font, r = 255, g = 255, b = 0)
img.paste(standing_timage, (x_offset, 22)) wins_timage = self.textImage('Wins:' + team['wins'], small_font, r = 0, g = 255, b = 0)
loss_timage = self.textImage('Losses:' + team['loss'], small_font, r = 255, g = 0, b = 0)
x_offset += max(points_timage.size[0], standing_timage.size[0]) + buff_size draw_timage = self.textImage('Draws:' + team['draw'], small_font, r = 0, g = 0, b = 255)
points_timage = self.textImage('Points:' + team['points'], small_font, r = 255, g = 255, b = 255)
standing_timage = self.textImage('Standing:' + team['standing'], small_font, r = 255, g = 255, b = 255)
img = img.crop((0,0,x_offset ,32))
return self.stitchImage([title_img, img])
img.paste(name_timage, (x_offset, -1))
img.paste(wins_timage, (x_offset, 12))
img.paste(loss_timage, (x_offset, 19))
img.paste(draw_timage, (x_offset, 26))
x_offset += max( wins_timage.size[0], loss_timage.size[0], draw_timage.size[0])
img.paste(points_timage, (x_offset, 14))
img.paste(standing_timage, (x_offset, 22))
x_offset += max(points_timage.size[0], standing_timage.size[0]) + buff_size
img = img.crop((0,0,x_offset ,32))
return self.stitchImage([title_img, img])
def getTodayWeatherImage(self): def getTodayWeatherImage(self):
f = open( "csv/weather_location.txt", 'r' ) all_settings = json.load(open('csv/current_weather.json', 'r'))
line = next(f)
locations = line.split(',') if all_settings['title']:
f.close() title_img = self.openImage('feature_titles/weather.png')
imgs = [title_img, self.blank]
else:
imgs = []
title_img = self.openImage('feature_titles/weather.png')
imgs = [title_img, self.blank] current_weathers = all_settings['locations']
current_weathers = json.load(open('csv/current_weather.json', 'r')) locations = list(current_weathers.keys())
for i, location in enumerate(locations): for i, location in enumerate(locations):
img = Image.new('RGB', (203, 32)) img = Image.new('RGB', (203, 32))
current_weather = current_weathers[i] current_weather = current_weathers[location]
small_font = ImageFont.load("./fonts/5x7.pil") small_font = ImageFont.load("./fonts/5x7.pil")
large_font = ImageFont.load("./fonts/10x20.pil") large_font = ImageFont.load("./fonts/10x20.pil")
@@ -1675,11 +1717,13 @@ class StockTicker():
daily_weathers = json.load(open('csv/daily_weather.json', 'r')) daily_weathers = json.load(open('csv/daily_weather.json', 'r'))
locations = list(daily_weathers['locations'].keys())
for i, location in enumerate(locations): for i, location in enumerate(locations):
img = Image.new('RGB', (1000, 32)) img = Image.new('RGB', (1000, 32))
current_weather = current_weathers[i] current_weather = current_weathers['locations'][location]
daily_weather = daily_weathers[i] daily_weather = daily_weathers['locations'][location]
small_font = ImageFont.load("./fonts/5x7.pil") small_font = ImageFont.load("./fonts/5x7.pil")
extra_small_font = ImageFont.load("./fonts/4x6.pil") extra_small_font = ImageFont.load("./fonts/4x6.pil")
@@ -1875,18 +1919,38 @@ class StockTicker():
def getUserImage(self): def getUserImage(self):
title_img = self.openImage('feature_titles/images.png') title_img = self.openImage('feature_titles/images.png')
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')) image = self.openImage(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'display_images/user_image.ppm'))
return self.stitchImage([title_img, image])
if all_settings['title']:
imgs = [title_img, image]
else:
imgs = [image]
return self.stitchImage(imgs)
def getUserGIF(self): def getUserGIF(self):
title_img = self.openImage('feature_titles/gifs.png') 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__)), 'display_images/user_gif.gif'))
f = open('csv/GIF_settings.json', 'r')
all_settings = json.load(f)
f.close()
frames = [] frames = []
for i, frame in enumerate(ImageSequence.Iterator(gif)): for i, frame in enumerate(ImageSequence.Iterator(gif)):
f = self.stitchImage([title_img, frame])
if all_settings['title']:
f = self.stitchImage([title_img, frame])
else:
f = self.stitchImage([frame])
frames.append(f) frames.append(f)
@@ -2127,7 +2191,7 @@ if __name__ == '__main__':
start_image = Image.open('./logos/startup_logo.png') start_image = Image.open('./logos/startup_logo.png')
stock_ticker.updateMultiple(['News']) stock_ticker.updateMultiple(['Stocks Prof', 'Crypto Prof', 'Forex Prof'])
stock_ticker.setImage(start_image) stock_ticker.setImage(start_image)
time.sleep(1) time.sleep(1)
stock_ticker.resetMatrix() stock_ticker.resetMatrix()