fixed temp conversion bug in wether

This commit is contained in:
Neythen Treloar 2022-04-10 12:50:10 +01:00
parent a38efd3626
commit 64f33c308b

View File

@ -1850,7 +1850,14 @@ class StockTicker():
logf.write('\n ' + "".join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2])))
logf.close()
return self.stitchImage(imgs)
def convertTemp(self,temp, setting):
if setting == 'kelvin':
temp = temp+ 273.15
elif setting == 'fahrenheit':
temp = temp*9/5 + 32
return temp
def getTodayWeatherImage(self):
@ -1887,21 +1894,21 @@ class StockTicker():
weather_dir = './logos/weather_icons'
weather_img = Image.open(weather_dir + '/weather_type_icons/' + weather_ids[main] + '.png')
temp = current_weather['temp']
feels_temp = current_weather['feels_like']
if all_settings['temp'] == 'kelvin':
temp = current_weather['temp'] + 273.15
elif all_settings['temp'] == 'fahrenheit':
feels_temp = current_weather['feels_like']*9/5 + 32
temp = current_weather['temp']*9/5 + 32
temp = self.convertTemp(current_weather['temp'], all_settings['temp'])
feels_temp = self.convertTemp(current_weather['feels_like'], all_settings['temp'])
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
deg_img = self.textImage('o', small_font)
main = current_weather['main_weather']
main_img = self.textImage(main.upper(), small_font)
feels_img = self.textImage('Feels like:'.upper() + str("{0:.0f}".format(feels_temp)), small_font)
min_img = self.textImage( "{0:.0f}".format(current_weather['min_temp']), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(current_weather['max_temp']), small_font, r=255, g=0, b=0)
min_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['min_temp'], all_settings['temp'])), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['max_temp'], all_settings['temp'])), small_font, r=255, g=0, b=0)
hum_img = Image.open(weather_dir + '/humidity.png')
htext_img = self.textImage(str(current_weather['humidity']) + '%', small_font)
uv_img = Image.open(weather_dir + '/uv.png')
@ -2084,10 +2091,10 @@ class StockTicker():
x_offset += deg_img.size[0] -2
min_img = self.textImage( "{0:.0f}".format(current_weather['min_temp']), small_font, r=0, g=0, b=255)
min_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['min_temp'], all_settings['temp'])), small_font, r=0, g=0, b=255)
img.paste(min_img, (x_offset+2, 2))
max_img = self.textImage( "{0:.0f}".format(current_weather['max_temp']), small_font, r=255, g=0, b=0)
max_img = self.textImage( "{0:.0f}".format(self.convertTemp(current_weather['max_temp'], all_settings['temp'])), small_font, r=255, g=0, b=0)
img.paste(max_img, (x_offset+2, 8))
x_offset += max_img.size[0] + 2
@ -2296,9 +2303,9 @@ class StockTicker():
imgs = []
daily_weathers = json.load(open('csv/daily_weather.json', 'r'))
f = open('csv/daily_weather.json', 'r')
daily_weathers = json.load(f)
f.close()
locations = list(daily_weathers['locations'].keys())
for i, location in enumerate(locations):
@ -2327,24 +2334,17 @@ class StockTicker():
temp = daily_weather[0]['temp']
min_temp = daily_weather[0]['min_temp']
max_temp = daily_weather[0]['max_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'])
if daily_weathers['temp'] == 'kelvin':
temp = daily_weather[0]['temp'] + 273.15
min_temp = daily_weather[0]['min_temp'] + 273.15
max_temp = daily_weather[0]['max_temp'] + 273.15
elif daily_weathers['temp'] == 'fahrenheit':
temp = daily_weather[0]['temp']*9/5 + 32
min_temp = daily_weather[0]['min_temp']*9/5 + 32
max_temp = daily_weather[0]['max_temp']*9/5 + 32
temp_img = self.textImage(str("{0:.0f}".format(temp)), large_font)
deg_img = self.textImage('o', small_font)
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)
min_img = self.textImage( "{0:.0f}".format(self.convertTemp(min_temp, daily_weathers['temp'])), small_font, r=0, g=0, b=255)
max_img = self.textImage( "{0:.0f}".format(self.convertTemp(max_temp, daily_weathers['temp'])), small_font, r=255, g=0, b=0)
main = daily_weather[0]['main_weather']
main_img = self.textImage(main.upper(), small_font)
@ -2445,7 +2445,7 @@ class StockTicker():
#img.paste(wind_img, (96,0))
#img.paste(wtext_img, (109,0))
#img.paste(date_img, (70, 0))
x_offset = 70
x_offset = 75
for i in range(1,len(daily_weather)-1):
weekday = weekdays[(datetime.today().weekday() + i)%7]
@ -2460,17 +2460,10 @@ class StockTicker():
min_temp = weather['min_temp']
max_temp = weather['max_temp']
min_temp = self.convertTemp(weather['min_temp'], daily_weathers['temp'])
max_temp = self.convertTemp(weather['max_temp'], daily_weathers['temp'])
if daily_weathers['temp'] == 'kelvin':
min_temp = weather['min_temp'] + 273.15
max_temp = weather['max_temp'] + 273.15
elif daily_weathers['temp'] == 'fahrenheit':
min_temp = weather['min_temp']*9/5 + 32
max_temp = weather['max_temp']*9/5 + 32
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)