daily weather prof

This commit is contained in:
Justin 2022-10-31 15:36:32 +08:00 committed by GitHub
parent 941f5632fe
commit fd010449ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,7 +72,7 @@ class StockTicker():
'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional, 'Stocks Prof': self.getStockProfessional, 'Crypto Prof': self.getCryptoProfessional, 'Forex Prof': self.getForexProfessional,
'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional} 'Current Weather Prof': self.getTodayWeatherProfessional, 'News Prof':self.getNewsProfessional, 'Commodities Prof':self.getCommoditiesProfessional, 'Indices Prof': self.getIndicesProfessional, 'Daily Forecast Prof':self.getDailyWeatherProfessional}
self.JSONs = {'Stocks': 'csv/stocks_settings.json', 'Crypto': 'csv/crypto_settings.json', 'Forex': 'csv/forex_settings.json', 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', 'Commodities':'csv/commodities_settings.json', 'Indices': 'csv/indices_settings.json', 'Daily Forecast':'csv/daily_weather.json', 'Current Weather': 'csv/current_weather.json', 'Commodities':'csv/commodities_settings.json', 'Indices': 'csv/indices_settings.json',
@ -80,7 +80,7 @@ class StockTicker():
'Sports (Upcoming Games)': 'csv/upcoming_games.json', 'Sports (Live Games)': 'csv/live_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', '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', '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', 'Commodities Prof':'csv/commodities_settings.json', 'Indices Prof': 'csv/indices_settings.json'} 'Current Weather Prof': 'csv/current_weather.json', 'News Prof':'csv/news_settings.json', 'Commodities Prof':'csv/commodities_settings.json', 'Indices Prof': 'csv/indices_settings.json', 'Daily Forecast Prof':'csv/daily_weather.json'}
def openImage(self, image_file): def openImage(self, image_file):
@ -2858,6 +2858,147 @@ class StockTicker():
return self.stitchImage(imgs) return self.stitchImage(imgs)
def getDailyWeatherProfessional(self):
f = open('csv/daily_weather.json', 'r')
all_settings = json.load(f)
f.close()
if all_settings['title']:
title_img = self.openImage('feature_titles/small_feature_titles/forecast.png')
image_list = [title_img, Image.new('RGB', (3, 16))]
else:
image_list = []
f = open('csv/daily_weather.json', 'r')
daily_weathers = json.load(f)
f.close()
locations = list(daily_weathers['locations'].keys())
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):
try:
img = Image.new('RGB', (1000, 32))
daily_weather = daily_weathers['locations'][location]
small_font = ImageFont.load("./fonts/4x6.pil")
font = ImageFont.load("./fonts/6x10.pil")
large_font = ImageFont.load("./fonts/10x20.pil")
main = daily_weather[0]['main_weather']
if main == 'Clouds':
main = daily_weather[0]['description']
if main == 'Rain':
main = daily_weather[0]['description']
weather_ids = {'Clear': '01', 'few clouds': '02', 'scattered clouds': '03', 'broken clouds':'04', 'overcast clouds':'04', 'Drizzle':'09',
'Rain':'10', 'Thunderstorm':'11', 'Snow':'13', 'Mist': '50', 'Smoke': '50', 'Haze': '50', 'Dust': '50', 'Fog': '50',
'Sand': '50', 'Ash': '50', 'Squall': '50', 'Tornado': '50', 'light rain': '10', 'moderate rain': '10', 'heavy intensity rain': '10',
'very heavy rain': '10', 'extreme rain': '10', 'freezing rain': '13', 'light intensity shower rain': '09', 'shower rain': '09',
'heavy intensity shower rain': '09', 'ragged shower rain': '09'}
weather_dir = './logos/weather_icons'
location_img = self.textImage(location.upper(), font, r = 255, g = 255, b = 0)
img.paste(location_img, (5,3))
x_offset = location_img.size[0] + 8
date_img = self.textImage((month + ' ' + date + ',' + weekday).upper(), font)
img.paste(date_img, (x_offset, 3))
x_offset += date_img.size[0] + 2
weather_img = Image.open(weather_dir + '/small_icons/' + weather_ids[main] + '.png')
w, h = weather_img.size
#weather_img = weather_img.resize((int(w/2), int(h/2)))
main = daily_weather[0]['main_weather']
main_img = self.textImage(main.upper(), font)
img.paste(main_img, (x_offset, 3))
x_offset += main_img.size[0] + 2
img.paste(weather_img, (x_offset,3))
x_offset += weather_img.size[0] + 2
temp = self.convertTemp(daily_weather[0]['temp'], daily_weathers['temp'])
temp_img = self.textImage(str("{0:.0f}".format(temp)), font)
img.paste(temp_img, (x_offset,3))
x_offset += temp_img.size[0]-3
deg_img = self.textImage('o', small_font)
img.paste(deg_img, (x_offset+1, 1))
x_offset += deg_img.size[0] -2
min_img = self.textImage( "{0:.0f}".format(self.convertTemp(daily_weather[0]['min_temp'], daily_weathers['temp'])), small_font, r=0, g=0, b=255)
img.paste(min_img, (x_offset+2, 2))
max_img = self.textImage( "{0:.0f}".format(self.convertTemp(daily_weather[0]['max_temp'], daily_weathers['temp'])), small_font, r=255, g=0, b=0)
img.paste(max_img, (x_offset+2, 8))
x_offset += max_img.size[0] + 15
crop_x = x_offset
for i in range(1,len(daily_weather)):
weekday = weekdays[(datetime.today().weekday() + i)%7]
day_img = self.textImage( weekday.upper(), font)
weather = daily_weather[i]
main = weather['main_weather']
if main == 'Clouds':
main = weather['description']
if main == 'Rain':
main = weather['description']
min_img = self.textImage( "{0:.0f}".format(self.convertTemp(weather['min_temp'], daily_weathers['temp'])), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(self.convertTemp(weather['max_temp'], daily_weathers['temp'])), small_font, r=255, g=0, b=0)
weather_img = Image.open(weather_dir + '/small_icons/' + weather_ids[main] + '.png')
img.paste(day_img, (x_offset, 3))
x_offset += (day_img.size[0])
img.paste(weather_img, (x_offset, 3))
x_offset += (weather_img.size[0]+2)
img.paste(min_img, (x_offset, 2))
img.paste(max_img, (x_offset, 8))
x_offset += (max(min_img.size[0], max_img.size[0])+5)
x_offset += 35
img1 = img.crop((0,0,x_offset,16))
# img1 = img.crop((0,0,max(x_offset, crop_x) ,16))
image_list.append(img1)
except Exception as e:
pass
return self.stitchImage(image_list)
def readSportsCSV(self, league): def readSportsCSV(self, league):
team_info = {} team_info = {}
@ -3029,6 +3170,7 @@ class StockTicker():
weather = self.getTodayWeatherProfessional() weather = self.getTodayWeatherProfessional()
commodities = self.getCommoditiesProfessional() commodities = self.getCommoditiesProfessional()
indices = self.getIndicesProfessional() indices = self.getIndicesProfessional()
daily_forecast = self.getDailyWeatherProfessional()
x_offset = 0 x_offset = 0
news.paste(weather, (x_offset, 16)) news.paste(weather, (x_offset, 16))
@ -3043,6 +3185,8 @@ class StockTicker():
x_offset += commodities.size[0] x_offset += commodities.size[0]
news.paste(indices, (x_offset, 16)) news.paste(indices, (x_offset, 16))
x_offset += indices.size[0] x_offset += indices.size[0]
news.paste(daily_forecast, (x_offset, 16))
x_offset += daily_forecast.size[0]
self.double_buffer = self.matrix.CreateFrameCanvas() self.double_buffer = self.matrix.CreateFrameCanvas()
while True: while True:
kill = stock_ticker.scrollImage(news, offset_x = 128) kill = stock_ticker.scrollImage(news, offset_x = 128)