Browse Source

[Feature] Neuronne OWM add specify country

monf 8 năm trước cách đây
mục cha
commit
4789bbad70
2 tập tin đã thay đổi với 9 bổ sung3 xóa
  1. 2 1
      brain.yml
  2. 7 2
      neurons/Openweathermap/Openweathermap.py

+ 2 - 1
brain.yml

@@ -11,10 +11,11 @@
   - name: "get the weather"
     neurons:
       - openweathermap:
-          api_key: "your-api"
+          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:

+ 7 - 2
neurons/Openweathermap/Openweathermap.py

@@ -12,16 +12,21 @@ class Openweathermap(NeuronModule):
         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(location)
+        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()
@@ -48,7 +53,7 @@ class Openweathermap(NeuronModule):
         clouds_coverage_tomorrow = weather_tomorrow.get_clouds()
 
         # Today
-        observation = owm.weather_at_place(location)
+        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')