Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create/amend rain/snow handle for "today/current" requests #26

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 40 additions & 19 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,21 +222,35 @@ def handle_forecast(self, message):
# Handle: When will it rain again? | Will it rain on Tuesday?
@intent_handler(IntentBuilder("NextPrecipitationIntent").require(
"Next").require("Precipitation").optionally("Location").build())
@intent_handler(IntentBuilder("CurrentRainSnowIntent").require(
"Query").require("Precipitation").optionally("Location").build())
def handle_next_precipitation(self, message):
report = self.__initialize_report(message)

# Get a date from spoken request
today = extract_datetime(" ")[0]
today = extract_datetime(" ")[0] # this is None
when = extract_datetime(message.data.get('utterance'))[0]

if today == when:
timeframe = 'today'
else:
timeframe = 'expected'

data = {
"modifier": "",
"precip": "none",
"day": self.__to_day(when),
"location" : report['location']
}

# search the forecast for precipitation
for weather in self.owm.daily_forecast(
report['full_location'],
report['lat'],
report['lon']).get_forecast().get_weathers():

forecastDate = datetime.fromtimestamp(weather.get_reference_time())


# TODO: "will it rain tomorrow" returns forecast for today, if it rains today
if when != today:
# User asked about a specific date, is this it?
whenGMT = self.__to_GMT(when)
Expand All @@ -245,35 +259,27 @@ def handle_next_precipitation(self, message):

rain = weather.get_rain()
if rain and rain["all"] > 0:
data = {
"modifier": "",
"precip": "rain",
"day": self.__to_day(forecastDate)
}
data["precip"] = "rain"
data["day"] = self.__to_day(forecastDate)
if rain["all"] < 10:
data["modifier"] = self.__translate("light")
elif rain["all"] > 20:
data["modifier"] = self.__translate("heavy")

self.speak_dialog("precipitation expected", data)
return
break

snow = weather.get_snow()
if snow and snow["all"] > 0:
data = {
"modifier": "",
"precip": "snow",
"day": self.__to_day(forecastDate)
}
data["precip"] = "snow"
data["day"] = self.__to_day(forecastDate)
if snow["all"] < 10:
data["modifier"] = self.__translate("light")
elif snow["all"] > 20:
data["modifier"] = self.__translate("heavy")

self.speak_dialog("precipitation expected", data)
return

self.speak_dialog("no precipitation expected", report)
break

self.__report_precipitation(timeframe, data)

# Handle: What's the weather later?
@intent_handler(IntentBuilder("NextHoursWeatherIntent").require(
Expand Down Expand Up @@ -485,6 +491,21 @@ def __initialize_report(self, message):
'full_location': location,
'scale': self.__get_temperature_unit()
}

def __report_precipitation(self, timeframe, data):
if data['precip'] == "none":
expected = ".not_expected"
elif timeframe == "today":
expected = ".today"
else:
expected = ".expected"

if data['location'] == self.location_pretty:
local = ".local"
else:
local = ""

self.speak_dialog("precipitation" + expected + local, data)

def __report_weather(self, timeframe, report):
# Tell the weather to the user (verbal and visual)
Expand Down
2 changes: 2 additions & 0 deletions dialog/de-de/precipitation.expected.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} wird am {{day}} in {{location}} erwartet
Die Vorhersage nennt {{modifier}} {{precip}} am {{day}} in {{location}}
4 changes: 4 additions & 0 deletions dialog/de-de/precipitation.not_expected.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
es wird kein Niederschlag in {{location}} erwartet
es wird nicht in {{location}} Regnen oder scheien
du brauchst nach {{location}} keinen Regenschirm mitnehmen

2 changes: 2 additions & 0 deletions dialog/de-de/precipitation.today.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} ist heute in {{location}} zu erwarten
Heute fällt in {{location}} {{modifier}} {{precip}}
2 changes: 2 additions & 0 deletions dialog/de-de/precipitation.today.local.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} ist heute zu erwarten
Heute fällt {{modifier}} {{precip}}
2 changes: 0 additions & 2 deletions dialog/en-us/no precipitation expected.dialog

This file was deleted.

2 changes: 0 additions & 2 deletions dialog/en-us/precipitation expected.dialog

This file was deleted.

3 changes: 3 additions & 0 deletions dialog/en-us/precipitation.expected.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{modifier}} {{precip}} is expected in {{location}} on {{day}}
{{modifier}} {{precip}} is expected on {{day}} for {{location}}
The forecast calls for {{modifier}} {{precip}} on {{day}} for {{location}}
5 changes: 5 additions & 0 deletions dialog/en-us/precipitation.expected.local.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{modifier}} {{precip}} is expected on {{day}}
The forecast calls for {{modifier}} {{precip}} on {{day}}
{{modifier}} {{precip}} is expected in {{location}} on {{day}}
{{modifier}} {{precip}} is expected on {{day}} for {{location}}
The forecast calls for {{modifier}} {{precip}} on {{day}} for {{location}}
2 changes: 2 additions & 0 deletions dialog/en-us/precipitation.not_expected.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
No precipitation is in the forecast for {{location}}
None is forecasted for {{location}}
4 changes: 4 additions & 0 deletions dialog/en-us/precipitation.not_expected.local.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
No precipitation is in the forecast
None is forecasted
No precipitation is in the forecast for {{location}}
None is forecasted for {{location}}
2 changes: 2 additions & 0 deletions dialog/en-us/precipitation.today.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Currently there is {{modifier}} {{precip}} in {{location}}
Today there is {{modifier}} {{precip}} in {{location}}
4 changes: 4 additions & 0 deletions dialog/en-us/precipitation.today.local.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Currently there is {{modifier}} {{precip}}
Today there is {{modifier}} {{precip}}
Currently there is {{modifier}} {{precip}} in {{location}}
Today there is {{modifier}} {{precip}} in {{location}}
2 changes: 2 additions & 0 deletions dialog/it-it/precipitatio.expected.local.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} è previsto per {{day}}
La previsione indica {{modifier}} {{precip}} per {{day}}
2 changes: 2 additions & 0 deletions dialog/it-it/precipitatio.today.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} è previsto
La previsione indica {{modifier}} {{precip}}
2 changes: 2 additions & 0 deletions dialog/it-it/precipitatio.today.local.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} è previsto
La previsione indica {{modifier}} {{precip}}
2 changes: 2 additions & 0 deletions dialog/it-it/precipitation.expected.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} è previsto per {{day}}
La previsione indica {{modifier}} {{precip}} per {{day}}
1 change: 1 addition & 0 deletions dialog/it-it/precipitation.not_expected.local.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nessuna precipitazione nelle previsioni
2 changes: 2 additions & 0 deletions dialog/it-it/precipitation.today.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{modifier}} {{precip}} è previsto
La previsione indica {{modifier}} {{precip}}
2 changes: 2 additions & 0 deletions vocab/en-us/Precipitation.voc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
rain
snow
raining
snowing
precipitation
rainy
snowy
2 changes: 2 additions & 0 deletions vocab/en-us/Query.voc
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ how
what is
tell
when
is it
does it
18 changes: 12 additions & 6 deletions vocab/en-us/WeatherType.voc
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
rain|raining
snow|snowing
rain
raining
snow
snowing
sleet
hail|hailing
sunny|sun
hot|warm
cold|cool
hail
hailing
sunny
sun
hot
warm
cold
cool