From: gregor herrmann Date: Sat, 9 Jun 2018 13:06:44 +0000 (+0200) Subject: owm.py: add rain/precipitation data X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/commitdiff_plain/e4f2c3354b555c39305f4d91c3be50f875e7ed72 owm.py: add rain/precipitation data they are only in the api response when OWM has rain data good test station: 3688451 https://openweathermap.org/city/3688451 Buenaventura, CO --- diff --git a/owm.py b/owm.py index 2fefc6a..71f3677 100755 --- a/owm.py +++ b/owm.py @@ -57,6 +57,7 @@ def extractweatherdata(w): windspeed=w.get('wind').get('speed'), winddegrees=w.get('wind').get('deg'), cloudiness=w.get('clouds').get('all'), + rain=w.get('rain'), ) data['sunrise_t'] = fromtimestamp(data['sunrise'], '%H:%M:%S') @@ -64,6 +65,10 @@ def extractweatherdata(w): data['date'] = fromtimestamp(data['datetime'], '%Y-%m-%d') data['time'] = fromtimestamp(data['datetime'], '%H:%M:%S') data['winddirection'] = degToCompass(data['winddegrees']) + if not data['rain'] is None: + data['precipitation']=data['rain'].get('3h') + else: + data['precipitation']='N/A' return data @@ -91,8 +96,8 @@ def main(): weather['sunrise_t'] + ';' + weather['sunset_t'] + ';' + str(weather['temp']) + ';' + - ';' + # precipitation missing? or only in XML: https://openweathermap.org/current ? - str(weather['windspeed']) + 'km/h ' + weather['winddirection'] + ';' + + str(weather['precipitation']) + ' mm/h;' + + str(weather['windspeed']) + ' km/h ' + weather['winddirection'] + ';' + weather['weather'] + ';' + str(weather['cloudiness']) )