Browse Source

Merge branch 'dev'

Conflicts:
	Docs/dev_env_install.md
	install/files/python_requirements.txt
nico 8 years ago
parent
commit
b28c369e61

+ 1 - 0
Docs/dev_env_install.md

@@ -31,6 +31,7 @@ pip install pygmail
 pip install pushetta
 pip install wakeonlan
 pip install ipaddress
+pip install pyowm
 ```
 
 ### Test your env

+ 15 - 1
brain.yml

@@ -8,6 +8,19 @@
     signals:
       - order: "push message"
 
+  - name: "get the weather"
+    neurons:
+      - openweathermap:
+          api_key: "fdfba4097c318aed7836b2a85a6a05ef"
+          lang: "fr"
+          temp_unit: "celsius"
+          location : "grenoble"
+          country: "FR"
+          say_template:
+          - "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"
+    signals:
+      - order: "quel temps fait-il "
+
   - name: "say hello"
     neurons:
       - say:
@@ -37,10 +50,11 @@
   - name: "Say local date"
     neurons:
       - systemdate:
+          tts: "voxygen"
           say_template:
             - "il est {{ hours }} heure et {{ minutes }} minute"
     signals:
-      - order: "what time is it"
+      - order: "quelle heure est-il"
 
   - name: "Say local date from template"
     neurons:

+ 1 - 0
core/MainController.py

@@ -14,6 +14,7 @@ from neurons import Say
 logging.basicConfig()
 logger = logging.getLogger("kalliope")
 
+
 class MainController:
     def __init__(self, brain_file=None):
         self.brain_file = brain_file

+ 1 - 0
install/files/python_requirements.txt

@@ -10,3 +10,4 @@ pygmail==0.0.5.4
 pushetta==1.0.15
 wakeonlan==0.2.2
 ipaddress==1.0.16
+pyowm==2.5.0

+ 1 - 0
neurons/__init__.py

@@ -7,5 +7,6 @@ from sleep import Sleep
 from systemdate import Systemdate
 from gmail_checker import Gmail_checker
 from push_message import Push_message
+from openweathermap import Openweathermap
 from tasker_autoremote import Tasker_autoremote
 from wake_on_lan import Wake_on_lan

+ 117 - 0
neurons/openweathermap/Openweathermap.py

@@ -0,0 +1,117 @@
+import pyowm
+
+from core.NeuronModule import NeuronModule
+
+
+class Openweathermap(NeuronModule):
+    def __init__(self, **kwargs):
+        # get message to spell out loud
+        super(Openweathermap, self).__init__(**kwargs)
+
+        api_key = kwargs.get('api_key', None)
+        location = kwargs.get('location', None)
+        lang = kwargs.get('lang', 'en')
+        temp_unit = kwargs.get('temp_unit', 'celsius')
+        country = kwargs.get('country', 'US')
+
+        if api_key is None:
+            raise NotImplementedError("OpenWeatherMap neuron needs an api_key")
+        if location is None:
+            raise NotImplementedError("OpenWeatherMap neuron needs a location")
+        extended_location = location
+        if country is not None:
+            extended_location = location + "," + country
+
+
+        owm = pyowm.OWM(API_key=api_key, language=lang)
+
+        # Tomorrow
+        forecast = owm.daily_forecast(extended_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(extended_location)
+        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']
+
+        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_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)
+
+

+ 95 - 0
neurons/openweathermap/README.md

@@ -0,0 +1,95 @@
+# 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 |                                                                                                   |
+| country   | No       | US      | multiple                    |  Frist 2 letters of the country cf API doc                                                        |
+
+## Return Values
+
+| Name                        | Description                                | Type   | sample                 |
+|-----------------------------|--------------------------------------------|--------|------------------------|
+| location                    | The current location                       | String | Grenoble               |
+| weather_today               | Today : The weather sentence               | String | cloudy                 |
+| 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 | sunny                  |
+| 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 }}"
+
+```
+
+You also can define the "location" args directly in neuron argument list. 
+
+```
+  - name: "get the weather"
+    neurons:
+      - openweathermap:
+          api_key: "fdfba4097c318aed7836b2a85a6a05ef"
+          lang: "fr"
+          temp_unit: "celsius"
+          location : "grenoble"
+          country: "FR"
+          say_template:
+          - "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"
+    signals:
+      - order: "quel temps fait-il "
+```
+
+## Templates example 
+
+
+```
+    Today in {{ location }} the weather is {{ weather_today }} with a temperature of {{ temp_today_temp }} degree
+```
+
+
+## Notes
+

+ 1 - 0
neurons/openweathermap/__init__.py

@@ -0,0 +1 @@
+from Openweathermap import Openweathermap