weather fixed

This commit is contained in:
Neythen 2021-12-04 15:54:31 +00:00
parent b038a574d0
commit b9a1316a0e
4 changed files with 43 additions and 32 deletions

View File

@ -343,9 +343,6 @@ def updateWeather():
for location in all_locations: for location in all_locations:
loc = gn.geocode(location) loc = gn.geocode(location)
current_weather = {} current_weather = {}
lat = loc.latitude lat = loc.latitude
@ -370,8 +367,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']
@ -383,10 +380,20 @@ def updateWeather():
dct['min_temp'] = day['temp']['min'] dct['min_temp'] = day['temp']['min']
dct['max_temp'] = day['temp']['max'] dct['max_temp'] = day['temp']['max']
daily_weather.append(dct) daily_weather.append(dct)
#add relevant urrent information to first day in daily
daily_weather[0]['temp'] = weather['temp']
daily_weather[0]['rain_chance'] = current_weather['rain_chance']
daily_weather[0]['humidity'] = current_weather['humidity']
daily_weather[0]['wind_speed'] = current_weather['wind_speed']
daily_weather[0]['uv'] = current_weather['uv']
daily_weather[0]['clouds'] = current_weather['clouds']
daily_weather[0]['wind_speed'] = current_weather['wind_speed']
daily_weather[0]['wind_direction'] = current_weather['wind_direction']
daily_weather[0]['visibility'] = current_weather['visibility']
if location in daily_locations:
daily_weathers[location] = daily_weather
daily_weathers[location] = daily_weather

View File

@ -414,9 +414,12 @@ def save_trade_settings(input_settings):
api_caller.sendline('f') api_caller.sendline('f')
def save_weather_settings(input_settings): def save_weather_settings(input_settings):
print(input_settings)
filename = 'current_weather.json' if input_settings['feature'] == 'Current Weather' else 'daily_weather.json' filename = 'current_weather.json' if input_settings['feature'] == 'Current Weather' else 'daily_weather.json'
print(filename)
current_settings = json.load(open('csv/' + filename, 'r')) current_settings = json.load(open('csv/' + filename, 'r'))
@ -431,8 +434,10 @@ def save_weather_settings(input_settings):
if input_settings['feature'] == 'Daily Forecast': if input_settings['feature'] == 'Daily Forecast':
current_settings['current_weather'] = input_settings['current_weather'] current_settings['current_weather'] = input_settings['current_weather']
locations = {}
current_settings = combine_dict(current_settings, input_settings['locations'], 'locations') for key in input_settings['locations']:
locations[key] = []
current_settings['locations'] = locations
json.dump(current_settings, open('csv/' + filename, 'w+')) json.dump(current_settings, open('csv/' + filename, 'w+'))

View File

@ -973,7 +973,7 @@ function saveSettings() {
s = getMessageSettings(page); s = getMessageSettings(page);
break; break;
} }
settings = { ...settings, ...s }; // merge both sets of settings settings = { ...settings, ...s }; // merge both sets of settings
fetch("/feature_settings", { fetch("/feature_settings", {

View File

@ -2063,7 +2063,7 @@ class StockTicker():
else: else:
imgs = [] imgs = []
current_weathers = json.load(open('csv/current_weather.json', 'r'))
daily_weathers = json.load(open('csv/daily_weather.json', 'r')) daily_weathers = json.load(open('csv/daily_weather.json', 'r'))
@ -2072,7 +2072,7 @@ class StockTicker():
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['locations'][location]
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")
@ -2081,12 +2081,9 @@ class StockTicker():
location_img = self.textImage(location.upper(), extra_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 = current_weather['main_weather']
if main == 'Clouds': if main == 'Clouds':
main = current_weather['description'] main = daily_weather['description']
weather_ids = {'Clear': '01', 'few clouds': '02', 'scattered clouds': '03', 'broken clouds':'04', 'overcast clouds':'04', 'Drizzle':'09', 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', 'Rain':'10', 'Thunderstorm':'11', 'Snow':'13', 'Mist': '50', 'Smoke': '50', 'Haze': '50', 'Dust': '50', 'Fog': '50',
'Sand': '50', 'Ash': '50', 'Squall': '50', 'Tornado': '50'} 'Sand': '50', 'Ash': '50', 'Squall': '50', 'Tornado': '50'}
@ -2094,12 +2091,12 @@ class StockTicker():
weather_dir = './logos/weather_icons' weather_dir = './logos/weather_icons'
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_img = self.textImage(str("{0:.0f}".format(current_weather['temp'])), large_font) temp_img = self.textImage(str("{0:.0f}".format(daily_weather[0]['temp'])), large_font)
deg_img = self.textImage('o', small_font) deg_img = self.textImage('o', small_font)
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(daily_weather[0]['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) max_img = self.textImage( "{0:.0f}".format(daily_weather[0]['max_temp']), small_font, r=255, g=0, b=0)
main = current_weather['main_weather'] main = daily_weather[0]['main_weather']
main_img = self.textImage(main.upper(), small_font) main_img = self.textImage(main.upper(), small_font)
weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] weekdays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
@ -2109,21 +2106,23 @@ class StockTicker():
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(), extra_small_font)
rain_img = Image.open(weather_dir + '/rain-chance.png') rain_img = Image.open(weather_dir + '/rain-chance.png')
rtext_img = self.textImage(str(int(current_weather['rain_chance']*100)) + '%', extra_small_font) rtext_img = self.textImage(str(int(daily_weather[0]['rain_chance']*100)) + '%', extra_small_font)
hum_img = Image.open(weather_dir + '/humidity.png') hum_img = Image.open(weather_dir + '/humidity.png')
htext_img = self.textImage(str(current_weather['humidity']) + '%', extra_small_font) htext_img = self.textImage(str(daily_weather[0]['humidity']) + '%', extra_small_font)
wind_img = Image.open(weather_dir + '/wind.png') wind_img = Image.open(weather_dir + '/wind.png')
wtext_img = self.textImage(str(current_weather['wind_speed']) + 'm/s'.upper(), extra_small_font) wtext_img = self.textImage(str(daily_weather[0]['wind_speed']) + 'm/s'.upper(), extra_small_font)
uv_img = Image.open(weather_dir + '/uv.png') uv_img = Image.open(weather_dir + '/uv.png')
utext_img = self.textImage(str(round(current_weather['uv'], 1)) , small_font) utext_img = self.textImage(str(round(daily_weather[0]['uv'], 1)) , small_font)
cloud_img = Image.open(weather_dir + '/clouds.png') cloud_img = Image.open(weather_dir + '/clouds.png')
ctext_img = self.textImage(str(current_weather['clouds']) + '%', small_font) ctext_img = self.textImage(str(daily_weather[0]['clouds']) + '%', small_font)
wind_img = Image.open(weather_dir + '/wind.png') wind_img = Image.open(weather_dir + '/wind.png')
wtext_img = self.textImage("{0:.0f}".format(current_weather['wind_speed']) + 'm/s'.upper(), small_font) wtext_img = self.textImage("{0:.0f}".format(daily_weather[0]['wind_speed']) + 'm/s'.upper(), small_font)
wdir_img = self.textImage(self.degreesToCompass(current_weather['wind_direction']), small_font) wdir_img = self.textImage(self.degreesToCompass(daily_weather[0]['wind_direction']), small_font)
vis_img = Image.open(weather_dir + '/visibility.png') vis_img = Image.open(weather_dir + '/visibility.png')
vtext_img = self.textImage(str(round(current_weather['visibility']/1000, 1)) + 'km'.upper(), small_font) 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))
@ -2434,7 +2433,7 @@ class StockTicker():
#userSettings = ['crypto', 'stocks'] # these wil be read from csv, just for demo #userSettings = ['crypto', 'stocks'] # these wil be read from csv, just for demo
#userSettings = [ 'display_image', 'news'] # these wil be read from csv, just for demo #userSettings = [ 'display_image', 'news'] # these wil be read from csv, just for demo
userSettings = json.load(open('csv/display_settings.json')) userSettings = json.load(open('csv/display_settings.json'))
if len(userSettings[1][0])>0 and len(userSettings[1][1])>0 and 'Professional'==userSettings[0] : #if professional display if 'Professional'==userSettings[0] and len(userSettings[1][0])>0 and len(userSettings[1][1])>0: #if professional display
self.scrollProfessionalAnimated(userSettings[1]) self.scrollProfessionalAnimated(userSettings[1])
elif len(userSettings[1])>0 and 'Standard'==userSettings[0]: elif len(userSettings[1])>0 and 'Standard'==userSettings[0]:
self.scrollFunctionsAnimated(userSettings[1], animation = 'down') self.scrollFunctionsAnimated(userSettings[1], animation = 'down')
@ -2473,7 +2472,7 @@ if __name__ == '__main__':
#stock_ticker.process_msg('G') #stock_ticker.process_msg('G')
#stock_ticker.process_msg('f') #stock_ticker.process_msg('f')
#stock_ticker.process_msg('W') #stock_ticker.process_msg('W')
stock_ticker.process_msg('A') #stock_ticker.process_msg('A')
while True: while True:
msg = getInput() msg = getInput()