Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e507ec6

Browse files
authoredFeb 12, 2018
Merge pull request #2 from nielstron/nielstron-patch-2
Taking care of locations in precipitation requests
2 parents fd375d3 + 17e7818 commit e507ec6

18 files changed

+71
-33
lines changed
 

‎__init__.py

+34-20
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,16 @@ def handle_next_precipitation(self, message):
231231
today = extract_datetime(" ")[0] # this is None
232232
when = extract_datetime(message.data.get('utterance'))[0]
233233
if today == when:
234-
forecasting = 'today'
234+
timeframe = 'today'
235235
else:
236-
forecasting = 'expected'
236+
timeframe = 'expected'
237+
238+
data = {
239+
"modifier": "",
240+
"precip": "none",
241+
"day": self.__to_day(when),
242+
"location" : report['location']
243+
}
237244

238245
# search the forecast for precipitation
239246
for weather in self.owm.daily_forecast(
@@ -242,8 +249,8 @@ def handle_next_precipitation(self, message):
242249
report['lon']).get_forecast().get_weathers():
243250

244251
forecastDate = datetime.fromtimestamp(weather.get_reference_time())
245-
246-
# TODO: "will it rain tomorrow" returns forecast for today, if it rains today
252+
253+
# TODO: "will it rain tomorrow" returns forecast for today, if it rains today
247254
if when != today:
248255
# User asked about a specific date, is this it?
249256
whenGMT = self.__to_GMT(when)
@@ -252,35 +259,27 @@ def handle_next_precipitation(self, message):
252259

253260
rain = weather.get_rain()
254261
if rain and rain["all"] > 0:
255-
data = {
256-
"modifier": "",
257-
"precip": "rain",
258-
"day": self.__to_day(forecastDate)
259-
}
262+
data["precip"] = "rain"
263+
data["day"] = self.__to_day(forecastDate)
260264
if rain["all"] < 10:
261265
data["modifier"] = self.__translate("light")
262266
elif rain["all"] > 20:
263267
data["modifier"] = self.__translate("heavy")
264268

265-
self.speak_dialog("precipitation." + forecasting, data)
266-
return
269+
break
267270

268271
snow = weather.get_snow()
269272
if snow and snow["all"] > 0:
270-
data = {
271-
"modifier": "",
272-
"precip": "snow",
273-
"day": self.__to_day(forecastDate)
274-
}
273+
data["precip"] = "snow"
274+
data["day"] = self.__to_day(forecastDate)
275275
if snow["all"] < 10:
276276
data["modifier"] = self.__translate("light")
277277
elif snow["all"] > 20:
278278
data["modifier"] = self.__translate("heavy")
279279

280-
self.speak_dialog("precipitation." + forecasting, data)
281-
return
282-
283-
self.speak_dialog("precipitation.not_expected", report)
280+
break
281+
282+
self.__report_precipitation(timeframe, data)
284283

285284
# Handle: What's the weather later?
286285
@intent_handler(IntentBuilder("NextHoursWeatherIntent").require(
@@ -492,6 +491,21 @@ def __initialize_report(self, message):
492491
'full_location': location,
493492
'scale': self.__get_temperature_unit()
494493
}
494+
495+
def __report_precipitation(self, timeframe, data):
496+
if data['precip'] == "none":
497+
expected = ".not_expected"
498+
elif timeframe == "today":
499+
expected = ".today"
500+
else:
501+
expected = ".expected"
502+
503+
if data['location'] == self.location_pretty:
504+
local = ".local"
505+
else:
506+
local = ""
507+
508+
self.speak_dialog("precipitation" + expected + local, data)
495509

496510
def __report_weather(self, timeframe, report):
497511
# Tell the weather to the user (verbal and visual)
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{{modifier}} {{precip}} wird am {{day}} erwartet
2-
Die Vorhersage nennt {{modifier}} {{precip}} am {{day}}
1+
{{modifier}} {{precip}} wird am {{day}} in {{location}} erwartet
2+
Die Vorhersage nennt {{modifier}} {{precip}} am {{day}} in {{location}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{modifier}} {{precip}} wird am {{day}} erwartet
2+
Die Vorhersage nennt {{modifier}} {{precip}} am {{day}}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
es wird kein Niederschlag erwartet
2-
es wird nicht Regnen oder scheien
3-
du brauchst keinen Regenschirm mitnehmen
1+
es wird kein Niederschlag in {{location}} erwartet
2+
es wird nicht in {{location}} Regnen oder scheien
3+
du brauchst nach {{location}} keinen Regenschirm mitnehmen
44

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
es wird kein Niederschlag erwartet
2+
es wird nicht Regnen oder scheien
3+
du brauchst keinen Regenschirm mitnehmen
4+
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{{modifier}} {{precip}} ist heute zu erwarten
2-
Heute fällt {{modifier}} {{precip}}
1+
{{modifier}} {{precip}} ist heute in {{location}} zu erwarten
2+
Heute fällt in {{location}} {{modifier}} {{precip}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{modifier}} {{precip}} ist heute zu erwarten
2+
Heute fällt {{modifier}} {{precip}}
+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
{{modifier}} {{precip}} is expected on {{day}}
2-
The forecast calls for {{modifier}} {{precip}} on {{day}}
1+
{{modifier}} {{precip}} is expected in {{location}} on {{day}}
2+
{{modifier}} {{precip}} is expected on {{day}} for {{location}}
3+
The forecast calls for {{modifier}} {{precip}} on {{day}} for {{location}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{modifier}} {{precip}} is expected on {{day}}
2+
The forecast calls for {{modifier}} {{precip}} on {{day}}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
No precipitation is in the forecast
2-
None is forecasted
1+
No precipitation is in the forecast for {{location}}
2+
None is forecasted for {{location}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
No precipitation is in the forecast
2+
None is forecasted
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Currently there is {{modifier}} {{precip}}
2-
Today there is {{modifier}} {{precip}}
1+
Currently there is {{modifier}} {{precip}} in {{location}}
2+
Today there is {{modifier}} {{precip}} in {{location}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Currently there is {{modifier}} {{precip}}
2+
Today there is {{modifier}} {{precip}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{modifier}} {{precip}} è previsto per {{day}}
2+
La previsione indica {{modifier}} {{precip}} per {{day}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{modifier}} {{precip}} è previsto per {{day}}
2+
La previsione indica {{modifier}} {{precip}} per {{day}}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{modifier}} {{precip}} è previsto
2+
La previsione indica {{modifier}} {{precip}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{{modifier}} {{precip}} è previsto
2+
La previsione indica {{modifier}} {{precip}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Nessuna precipitazione nelle previsioni

0 commit comments

Comments
 (0)
Please sign in to comment.