Browse Source

[Feature] Doc + improvement -> Neuron Weather with the OpenWeatherMap API

monf 8 years ago
parent
commit
ff382c0e20
3 changed files with 158 additions and 9 deletions
  1. 5 3
      brain.yml
  2. 76 6
      neurons/Openweathermap/Openweathermap.py
  3. 77 0
      neurons/Openweathermap/README.md

+ 5 - 3
brain.yml

@@ -11,10 +11,11 @@
   - name: "get the weather"
     neurons:
       - openweathermap:
-          api_key: "your_api"
+          api_key: "your-api"
           lang: "fr"
+          temp_unit: "celsius"
           say_template:
-          - "Aujourd'hui a {{ location }} le temps est {{ weather }}, demain il sera {{ weather_tomorrow }}"
+          - "Aujourd'hui a {{ location }} le temps est {{ weather_today }} avec une température de {{ temp_today_temp }} degrés et demain le temps sera {{ weather_tomorrow }} avec une température de {{ temp_tomorrow_temp }} degrés"
           args:
           - location
     signals:
@@ -49,11 +50,12 @@
   - name: "Say local date"
     neurons:
       - systemdate:
+          tts: "voxygen"
           say_template:
             - "il est {{ hours }} heure et {{ minutes }} minute"
           cache: False
     signals:
-      - order: "what time is it"
+      - order: "quelle heure est-il"
 
   - name: "Say local date from template"
     neurons:

+ 76 - 6
neurons/Openweathermap/Openweathermap.py

@@ -11,6 +11,7 @@ class Openweathermap(NeuronModule):
         api_key = kwargs.get('api_key', None)
         location = kwargs.get('location', None)
         lang = kwargs.get('lang', 'en')
+        temp_unit = kwargs.get('temp_unit', 'celsius')
 
         if api_key is None:
             raise NotImplementedError("OpenWeatherMap neuron needs an api_key")
@@ -19,22 +20,91 @@ class Openweathermap(NeuronModule):
 
         owm = pyowm.OWM(API_key=api_key, language=lang)
 
+        # Tomorrow
         forecast = owm.daily_forecast(location)
         tomorrow = pyowm.timeutils.tomorrow()
         weather_tomorrow = forecast.get_weather_at(tomorrow)
         weather_tomorrow_status = weather_tomorrow.get_detailed_status()
+        sunset_time_tomorrow = weather_tomorrow.get_sunset_time('iso')
+        sunrise_time_tomorrow = weather_tomorrow.get_sunrise_time('iso')
 
+        temp_tomorrow = weather_tomorrow.get_temperature(unit=temp_unit)
+        temp_tomorrow_temp = temp_tomorrow['day']
+        temp_tomorrow_temp_max = temp_tomorrow['max']
+        temp_tomorrow_temp_min = temp_tomorrow['min']
+
+        pressure_tomorrow = weather_tomorrow.get_pressure()
+        pressure_tomorrow_press = pressure_tomorrow['press']
+        pressure_tomorrow_sea_level = pressure_tomorrow['sea_level']
+
+        humidity_tomorrow = weather_tomorrow.get_humidity()
+
+        wind_tomorrow = weather_tomorrow.get_wind()
+        # wind_tomorrow_deg = wind_tomorrow['deg']
+        wind_tomorrow_speed = wind_tomorrow['speed']
+
+        snow_tomorrow = weather_tomorrow.get_snow()
+        rain_tomorrow = weather_tomorrow.get_rain()
+        clouds_coverage_tomorrow = weather_tomorrow.get_clouds()
+
+        # Today
         observation = owm.weather_at_place(location)
-        weather = observation.get_weather()
-        weather_status = weather.get_detailed_status()
+        weather_today = observation.get_weather()
+        weather_today_status = weather_today.get_detailed_status()
+        sunset_time_today = weather_today.get_sunset_time('iso')
+        sunrise_time_today = weather_today.get_sunrise_time('iso')
+
+        temp_today = weather_today.get_temperature(unit=temp_unit)
+        temp_today_temp = temp_today['temp']
+        temp_today_temp_max = temp_today['temp_max']
+        temp_today_temp_min = temp_today['temp_min']
 
-        print "weather :", weather_status
-        print "weather_tomorrow :", weather_tomorrow_status
+        pressure_today = weather_today.get_pressure()
+        pressure_today_press = pressure_today['press']
+        pressure_today_sea_level = pressure_today['sea_level']
+
+        humidity_today = weather_today.get_humidity()
+
+        wind_today= weather_today.get_wind()
+        wind_today_deg = wind_today['deg']
+        wind_today_speed = wind_today['speed']
+
+        snow_today = weather_today.get_snow()
+        rain_today = weather_today.get_rain()
+        clouds_coverage_today = weather_today.get_clouds()
 
         message = {
             "location": location,
-            "weather": weather_status,
-            "weather_tomorrow":weather_tomorrow_status
+
+            "weather_today": weather_today_status,
+            "sunset_today_time": sunset_time_today,
+            "sunrise_today_time": sunrise_time_today,
+            "temp_today_temp": temp_today_temp,
+            "temp_today_temp_max": temp_today_temp_max,
+            "temp_today_temp_min": temp_today_temp_min,
+            "pressure_today_press": pressure_today_press,
+            "pressure_today_sea_level": pressure_today_sea_level,
+            "humidity_today": humidity_today,
+            "wind_today_deg": wind_today_deg,
+            "wind_today_speed": wind_today_speed,
+            "snow_today": snow_today,
+            "rain_today": rain_today,
+            "clouds_coverage_today": clouds_coverage_today,
+
+            "weather_tomorrow": weather_tomorrow_status,
+            "sunset_time_tomorrow": sunset_time_tomorrow,
+            "sunrise_time_tomorrow": sunrise_time_tomorrow,
+            "temp_tomorrow_temp": temp_tomorrow_temp,
+            "temp_tomorrow_temp_max": temp_tomorrow_temp_max,
+            "temp_tomorrow_temp_min": temp_tomorrow_temp_min,
+            "pressure_tomorrow_press": pressure_tomorrow_press,
+            "pressure_tomorrow_sea_level": pressure_tomorrow_sea_level,
+            "humidity_tomorrow": humidity_tomorrow,
+            # "wind_tomorrow_deg": wind_tomorrow_deg,
+            "wind_tomorrow_speed": wind_tomorrow_speed,
+            "snow_tomorrow": snow_tomorrow,
+            "rain_tomorrow": rain_tomorrow,
+            "clouds_coverage_tomorrow": clouds_coverage_tomorrow
         }
 
         self.say(message)

+ 77 - 0
neurons/Openweathermap/README.md

@@ -0,0 +1,77 @@
+# OpenWeatherMap API
+
+## Synopsis 
+
+Give the today and tomorrow weather with the related data (humidity, temperature, etc ...) for a given location. 
+
+## Options
+
+| parameter | required | default | choices                     | comment                                                                                           |
+|-----------|----------|---------|-----------------------------|---------------------------------------------------------------------------------------------------|
+| api_key   | YES      | None    |                             | User API key of the OWM API                                                                       |
+| location  | YES      | None    |                             | The location                                                                                      |
+| lang      | No       | en      | multiple                    | First 2 letters cf : section Multilingual support in : [lang](https://openweathermap.org/current) |
+| temp_unit | No       | Kelvin  | Celsius, Kelvin, Fahrenheit |                                                                                                   |
+
+## Return Values
+
+| Name                        | Description                                | Type   | sample                 |
+|-----------------------------|--------------------------------------------|--------|------------------------|
+| location                    | The current location                       | String | Grenoble               |
+| weather_today               | Today : The weather sentence               | String | nuageux                |
+| sunset_today_time           | Today : The sunset time (iso)              | String | 2016-10-15 20:07:57+00 |
+| sunrise_today_time          | Today : The sunrise time (iso)             | String | 2016-10-15 07:07:57+00 |
+| temp_today_temp             | Today : Average temperature                | float  | 25                     |
+| temp_today_temp_max         | Today : Max temperature                    | float  | 45                     |
+| temp_today_temp_min         | Today : Min temperatue                     | float  | 5                      |
+| pressure_today_press        | Today : Pressure                           | float  | 1009                   |
+| pressure_today_sea_level    | Today : Pressure at the Sea level          | float  | 1038.381               |
+| humidity_today              | Today : % of humidity                      | float  | 60                     |
+| wind_today_deg              | Today : Direction of the wind in degree    | float  | 45                     |
+| wind_today_speed            | Today : Wind speed                         | float  | 2.66                   |
+| snow_today                  | Today : Volume of snow                     | float  | 0                      |
+| rain_today                  | Today : Rain volume                        | float  | 0                      |
+| clouds_coverage_today       | Today : % Cloud coverage                   | float  | 65                     |
+| weather_tomorrow            | Tomorrow : The weather sentence            | String | ensoleillé             |
+| sunset_time_tomorrow        | Tomorrow : The sunset time (iso)           | String | 2016-10-16 20:07:57+00 |
+| sunrise_time_tomorrow       | Tomorrow : The sunrise time (iso)          | String | 2016-10-16 07:07:57+00 |
+| temp_tomorrow_temp          | Tomorrow : Average temperature             | float  | 25                     |
+| temp_tomorrow_temp_max      | Tomorrow : Max temperature                 | float  | 45                     |
+| temp_tomorrow_temp_min      | Tomorrow : Min temperatue                  | float  | 5                      |
+| pressure_tomorrow_press     | Tomorrow : Pressure                        | float  | 1009                   |
+| pressure_tomorrow_sea_level | Tomorrow : Pressure at the Sea level       | float  | 1038.381               |
+| humidity_tomorrow           | Tomorrow : % of humidity                   | float  | 60                     |
+| wind_tomorrow_deg           | Tomorrow : Direction of the wind in degree | float  | 45                     |
+| wind_tomorrow_speed         | Tomorrow : Wind speed                      | float  | 2.66                   |
+| snow_tomorrow               | Tomorrow : Volume of snow                  | float  | 0                      |
+| rain_tomorrow               | Tomorrow : Rain volume                     | float  | 0                      |
+| clouds_coverage_tomorrow    | Tomorrow : % Cloud coverage                | float  | 65                     |
+
+## Synapses example
+
+```
+  - name: "get the weather"
+    neurons:
+      - openweathermap:
+          api_key: "fdfba4097c318aed7836b2a85a6a05ef"
+          lang: "en"
+          temp_unit: "celsius"
+          say_template:
+          - "Today in {{ location }} the weather is {{ weather_today }} with a temperature of {{ temp_today_temp }} degree and tomorrow the weather will be {{ weather_tomorrow }} with a temperature of {{ temp_tomorrow_temp }} degree"
+          args:
+          - location
+    signals:
+      - order: "what is the weather in {{ location }}"
+
+```
+
+## Templates example 
+
+
+```
+    Today in {{ location }} the weather is {{ weather_today }} with a temperature of {{ temp_today_temp }} degree
+```
+
+
+## Notes
+