Rain in hourly weather now displayed correctly

Was a dict conntaining '1h' as key. The value for this key is now used.
Also renamed get_weather() to query_weather() as it is not a getter but querying the api.
This commit is contained in:
JuliusFreudenberger 2020-09-24 11:03:16 +02:00
parent f6d0db3f41
commit 1b6afde312

View file

@ -31,7 +31,7 @@ class HourlyWeather:
self.wind_speed = json_data['wind_speed'] self.wind_speed = json_data['wind_speed']
self.probability_of_precipitation = json_data['pop'] self.probability_of_precipitation = json_data['pop']
if 'rain' in json_data: if 'rain' in json_data:
self.rain = json_data['rain'] self.rain = json_data['rain']['1h']
else: else:
self.rain = 0 self.rain = 0
self.main = json_data['weather'][0]['main'] self.main = json_data['weather'][0]['main']
@ -131,7 +131,7 @@ class City:
self.lat = lat self.lat = lat
self.lon = lon self.lon = lon
def get_weather(self): def query_weather(self):
request = requests.get( request = requests.get(
"http://api.openweathermap.org/data/2.5/onecall?\ "http://api.openweathermap.org/data/2.5/onecall?\
lang=de&units=metric&exclude=minutely&lat={lat}&lon={lon}&appid={token}".format( lang=de&units=metric&exclude=minutely&lat={lat}&lon={lon}&appid={token}".format(
@ -193,7 +193,7 @@ def handle_weather(update, context):
requested_city = get_city_by_name(' '.join(context.args)) requested_city = get_city_by_name(' '.join(context.args))
if requested_city.name == "none": if requested_city.name == "none":
raise WeatherStationNotFoundError raise WeatherStationNotFoundError
requested_city.get_weather() requested_city.query_weather()
update.message.reply_text(str(requested_city.weather), disable_notification=True, parse_mode="Markdown") update.message.reply_text(str(requested_city.weather), disable_notification=True, parse_mode="Markdown")
requested_city.weather.clear() requested_city.weather.clear()