disable enable current weather, fixed spacing

This commit is contained in:
Justin 2023-04-14 15:32:24 +08:00 committed by GitHub
parent ced479f28f
commit 8ab7361a57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4147,14 +4147,12 @@ class StockTicker():
all_settings = json.load(f) all_settings = json.load(f)
f.close() f.close()
if all_settings['title']: if all_settings['title']:
title_img = self.openImage('feature_titles/forecast.png') title_img = self.openImage('feature_titles/forecast.png')
imgs = [title_img, self.blank] imgs = [title_img, self.blank]
else: else:
imgs = [] imgs = []
f = open('csv/daily_weather.json', 'r') f = open('csv/daily_weather.json', 'r')
daily_weathers = json.load(f) daily_weathers = json.load(f)
f.close() f.close()
@ -4164,15 +4162,13 @@ class StockTicker():
try: try:
img = Image.new('RGB', (1000, 32)) img = Image.new('RGB', (1000, 32))
daily_weather = daily_weathers['locations'][location] 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")
large_font = ImageFont.load("./fonts/10x20.pil") large_font = ImageFont.load("./fonts/10x20.pil")
location_img = self.textImage(location.upper(), small_font, r = 255, g = 255, b = 0)
location_img = self.textImage(location.upper(), extra_small_font, r = 255, g = 255, b = 0)
main = daily_weather[0]['main_weather'] main = daily_weather[0]['main_weather']
if main == 'Clouds': if main == 'Clouds':
main = daily_weather[0]['description'] main = daily_weather[0]['description']
@ -4188,14 +4184,10 @@ class StockTicker():
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png') weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
temp = self.convertTemp(daily_weather[0]['temp'], daily_weathers['temp']) temp = self.convertTemp(daily_weather[0]['temp'], daily_weathers['temp'])
min_temp = self.convertTemp(daily_weather[0]['min_temp'], daily_weathers['temp']) min_temp = self.convertTemp(daily_weather[0]['min_temp'], daily_weathers['temp'])
max_temp = self.convertTemp(daily_weather[0]['max_temp'], daily_weathers['temp']) max_temp = self.convertTemp(daily_weather[0]['max_temp'], daily_weathers['temp'])
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font) temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
deg_img = self.textImage('o', small_font) deg_img = self.textImage('o', small_font)
@ -4210,39 +4202,35 @@ class StockTicker():
month = months[int(datetime.now().strftime('%m'))-1] month = months[int(datetime.now().strftime('%m'))-1]
date = str(int(datetime.now().strftime('%d'))) date = str(int(datetime.now().strftime('%d')))
weekday = weekdays[datetime.today().weekday()] weekday = weekdays[datetime.today().weekday()]
date_img = self.textImage((month + ' ' + date + ',' + weekday).upper(), extra_small_font) date_img = self.textImage((month + ' ' + date + ',' + weekday).upper(), small_font)
if daily_weathers['current_weather']:
rain_img = Image.open(weather_dir + '/rain-chance.png')
rtext_img = self.textImage(str(int(daily_weather[0]['rain_chance']*100)) + '%', small_font)
hum_img = Image.open(weather_dir + '/humidity.png')
htext_img = self.textImage(str(daily_weather[0]['humidity']) + '%', small_font)
wind_img = Image.open(weather_dir + '/wind.png')
wtext_img = self.textImage(str(daily_weather[0]['wind_speed']) + 'm/s'.upper(), small_font)
uv_img = Image.open(weather_dir + '/uv.png')
utext_img = self.textImage(str(round(daily_weather[0]['uv'], 1)) , small_font)
cloud_img = Image.open(weather_dir + '/clouds.png')
ctext_img = self.textImage(str(daily_weather[0]['clouds']) + '%', small_font)
wind_img = Image.open(weather_dir + '/wind.png')
rain_img = Image.open(weather_dir + '/rain-chance.png') w_speed = daily_weather[0]['wind_speed']*3.6
rtext_img = self.textImage(str(int(daily_weather[0]['rain_chance']*100)) + '%', extra_small_font) w_unit = 'K/H'
hum_img = Image.open(weather_dir + '/humidity.png') if daily_weathers['wind_speed'] == "miles/hour":
htext_img = self.textImage(str(daily_weather[0]['humidity']) + '%', extra_small_font) w_speed = daily_weather[0]['wind_speed']*2.236936
wind_img = Image.open(weather_dir + '/wind.png') w_unit = 'M/H'
wtext_img = self.textImage(str(daily_weather[0]['wind_speed']) + 'm/s'.upper(), extra_small_font)
uv_img = Image.open(weather_dir + '/uv.png')
utext_img = self.textImage(str(round(daily_weather[0]['uv'], 1)) , small_font)
cloud_img = Image.open(weather_dir + '/clouds.png')
ctext_img = self.textImage(str(daily_weather[0]['clouds']) + '%', small_font)
wind_img = Image.open(weather_dir + '/wind.png')
w_speed = daily_weather[0]['wind_speed']*3.6
w_unit = 'K/H'
if daily_weathers['wind_speed'] == "miles/hour":
w_speed = daily_weather[0]['wind_speed']*2.236936
w_unit = 'M/H'
wtext_img = self.textImage("{0:.0f}".format(w_speed) + w_unit, small_font)
wdir_img = self.textImage(self.degreesToCompass(daily_weather[0]['wind_direction']), small_font)
vis_img = Image.open(weather_dir + '/visibility.png')
vtext_img = self.textImage(str(round(daily_weather[0]['visibility']/1000, 1)) + 'km'.upper(), small_font)
wtext_img = self.textImage("{0:.0f}".format(w_speed) + w_unit, small_font)
wdir_img = self.textImage(self.degreesToCompass(daily_weather[0]['wind_direction']), small_font)
vis_img = Image.open(weather_dir + '/visibility.png')
vtext_img = self.textImage(str(round(daily_weather[0]['visibility']/1000, 1)) + 'km'.upper(), small_font)
img.paste(location_img, (0,0)) img.paste(location_img, (0,0))
x_offset = location_img.size[0]+2 x_offset2 = location_img.size[0]+5
img.paste(weather_img, (5,9)) img.paste(weather_img, (5,9))
x_offset = 5 + weather_img.size[0] + 1 x_offset = 5 + weather_img.size[0] + 1
@ -4254,54 +4242,46 @@ class StockTicker():
x_offset += max( main_img.size[0], temp_img.size[0] + deg_img.size[0]) x_offset += max( main_img.size[0], temp_img.size[0] + deg_img.size[0])
img.paste(min_img, (x_offset - 0, 12)) img.paste(min_img, (x_offset - 0, 12))
img.paste(max_img, (x_offset - 0, 21)) img.paste(max_img, (x_offset - 0, 21))
x_offset += max(min_img.size[0], max_img.size[0]) + 2 x_offset += max(min_img.size[0], max_img.size[0]) + 2
img.paste(date_img, (x_offset, 1)) img.paste(date_img, (x_offset2, 0))
x_offset += date_img.size[0]+2 x_offset2 += date_img.size[0]+5
img.paste(rain_img, (x_offset,0)) if daily_weathers['current_weather']:
x_offset += rain_img.size[0]+2 img.paste(rain_img, (x_offset2,0))
img.paste(rtext_img, (x_offset, 1)) x_offset2 += rain_img.size[0]+2
x_offset += rtext_img.size[0]+2 img.paste(rtext_img, (x_offset2,1))
x_offset2 += rtext_img.size[0]+2
img.paste(hum_img, (x_offset, 0)) img.paste(hum_img, (x_offset2, 0))
x_offset += hum_img.size[0]+2 x_offset2 += hum_img.size[0]+2
img.paste(htext_img, (x_offset, 1)) img.paste(htext_img, (x_offset2, 1))
x_offset+= htext_img.size[0]+2 x_offset2+= htext_img.size[0]+2
img.paste(uv_img, ( x_offset, 0)) img.paste(uv_img, ( x_offset2, 0))
x_offset += uv_img.size[0]+2 x_offset2 += uv_img.size[0]+2
img.paste(utext_img, (x_offset, 1)) img.paste(utext_img, (x_offset2, 1))
x_offset += utext_img.size[0]+2 x_offset2 += utext_img.size[0]+2
img.paste(cloud_img, (x_offset,0)) img.paste(cloud_img, (x_offset2,0))
x_offset += cloud_img.size[0]+2 x_offset2 += cloud_img.size[0]+2
img.paste(ctext_img, (x_offset, 1)) img.paste(ctext_img, (x_offset2, 1))
x_offset += ctext_img.size[0]+2 x_offset2 += ctext_img.size[0]+2
img.paste(wind_img, (x_offset,0)) img.paste(wind_img, (x_offset2,0))
x_offset += wind_img.size[0]+2 x_offset2 += wind_img.size[0]+2
img.paste(wtext_img, (x_offset, 1)) img.paste(wtext_img, (x_offset2, 1))
x_offset += wtext_img.size[0]+2 x_offset2 += wtext_img.size[0]+2
img.paste(wdir_img, (x_offset, 1)) img.paste(wdir_img, (x_offset2, 1))
x_offset+= wdir_img.size[0]+2 x_offset2+= wdir_img.size[0]+2
img.paste(vis_img, (x_offset,0)) img.paste(vis_img, (x_offset2,-1))
x_offset+= vis_img.size[0]+2 x_offset2+= vis_img.size[0]+2
img.paste(vtext_img, (x_offset, 1)) img.paste(vtext_img, (x_offset2, 1))
x_offset += vtext_img.size[0] +2 x_offset2 += vtext_img.size[0] +2
crop_x = x_offset
#img.paste(uv_img, ( 96, 0))
#img.paste(utext_img, (109, 0))
#img.paste(wind_img, (96,0))
#img.paste(wtext_img, (109,0))
#img.paste(date_img, (70, 0))
x_offset = 77
for i in range(1,len(daily_weather)): for i in range(1,len(daily_weather)):
weekday = weekdays[(datetime.today().weekday() + i)%7] weekday = weekdays[(datetime.today().weekday() + i)%7]
@ -4310,22 +4290,17 @@ class StockTicker():
weather = daily_weather[i] weather = daily_weather[i]
main = weather['main_weather'] main = weather['main_weather']
if main == 'Clouds': if main == 'Clouds':
main = weather['description'] main = weather['description']
if main == 'Rain': if main == 'Rain':
main = weather['description'] main = weather['description']
min_temp = self.convertTemp(weather['min_temp'], daily_weathers['temp']) min_temp = self.convertTemp(weather['min_temp'], daily_weathers['temp'])
max_temp = self.convertTemp(weather['max_temp'], daily_weathers['temp']) max_temp = self.convertTemp(weather['max_temp'], daily_weathers['temp'])
weather_img = Image.open(weather_dir + '/small_icons/' + weather_ids[main] + '.png') weather_img = Image.open(weather_dir + '/small_icons/' + weather_ids[main] + '.png')
min_img = self.textImage( "{0:.0f}".format(min_temp), small_font, r=0, g=0, b=255) min_img = self.textImage( "{0:.0f}".format(min_temp), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(max_temp), small_font, r=255, g=0, b=0) max_img = self.textImage( "{0:.0f}".format(max_temp), small_font, r=255, g=0, b=0)
img.paste(day_img, (x_offset +5, 9)) img.paste(day_img, (x_offset +5, 9))
@ -4335,7 +4310,7 @@ class StockTicker():
x_offset += 43 x_offset += 43
img1 = img.crop((0,0,max(x_offset, crop_x) ,32)) img1 = img.crop((0,0,max(x_offset, x_offset2 + 10) ,32))
imgs.append(img1) imgs.append(img1)
imgs.append(self.blank) imgs.append(self.blank)
# add the image text # add the image text