Browse Source

[Feature] Neurons first implementation OpenWeatherMap

monf 8 years ago
parent
commit
8613c9e62b

+ 9 - 0
brain.yml

@@ -8,6 +8,15 @@
     signals:
       - order: "push message"
 
+  - name: "get the weather"
+    neurons:
+      - openweathermap:
+          api_key: "your_key"
+          say_template:
+          - "Les prévisions pour {{ date }} sont {{ weather }}"
+    signals:
+      - order: "{{ date }} quel temps fait-il a {{ location }}"
+
   - name: "say hello"
     neurons:
       - say:

+ 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

@@ -8,3 +8,4 @@ python-crontab==2.1.1
 cffi==1.8.3
 pygmail==0.0.5.4
 pushetta==1.0.15
+pyowm==2.5.0

+ 37 - 0
neurons/OpenWeatherMap/OpenWeatherMap.py

@@ -0,0 +1,37 @@
+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)
+        date = kwargs.get('date', None)
+
+        if api_key is None:
+            raise NotImplementedError("OpenWeatherMap neuron needs an api_key")
+        if location is None:
+            raise NotImplementedError("OpenWeatherMap neuron needs a location")
+
+        owm = pyowm.OWM(api_key)
+
+
+        # forecast = owm.daily_forecast(location)
+        # tomorrow = pyowm.timeutils.tomorrow()
+        # forecast.will_be_sunny_at(tomorrow)
+
+        observation = owm.weather_at_place(location)
+        weather = observation.get_weather()
+
+        message = {
+            "date": date,
+            "weathers": weather,
+        }
+
+        self.say(message)
+
+

+ 3 - 0
neurons/OpenWeatherMap/__init__.py

@@ -0,0 +1,3 @@
+from OpenWeatherMap import OpenWeatherMap
+
+