#487 - Checking if location exists if doesn't say location not found dialog
parent
d1068ab3ac
commit
3e092554e3
|
@ -32,7 +32,7 @@
|
||||||
"stop_threshold": 2.0
|
"stop_threshold": 2.0
|
||||||
},
|
},
|
||||||
"server": {
|
"server": {
|
||||||
"url": "https://api-test.mycroft.ai",
|
"url": "https://api.mycroft.ai",
|
||||||
"version": "v1",
|
"version": "v1",
|
||||||
"update": true,
|
"update": true,
|
||||||
"metrics": false
|
"metrics": false
|
||||||
|
|
|
@ -46,30 +46,25 @@ class OWMApi(Api):
|
||||||
params.get("query").update({"lang": self.lang})
|
params.get("query").update({"lang": self.lang})
|
||||||
return params.get("query")
|
return params.get("query")
|
||||||
|
|
||||||
def build_location(self, location):
|
|
||||||
city = location.get("city", {})
|
|
||||||
return city.get("name", "Lawrence") + ", " + city.get("state", {}).get("name", "Kansas") + ", " + \
|
|
||||||
city.get("state", {}).get("country", {}).get("name", "United States")
|
|
||||||
|
|
||||||
def get_data(self, response):
|
def get_data(self, response):
|
||||||
return response.text
|
return response.text
|
||||||
|
|
||||||
def weather_at_place(self, location):
|
def weather_at_place(self, name):
|
||||||
data = self.request({
|
data = self.request({
|
||||||
"path": "/weather",
|
"path": "/weather",
|
||||||
"query": {"q": self.build_location(location)}
|
"query": {"q": name}
|
||||||
})
|
})
|
||||||
return self.observation.parse_JSON(data)
|
return self.observation.parse_JSON(data)
|
||||||
|
|
||||||
def three_hours_forecast(self, location):
|
def three_hours_forecast(self, name):
|
||||||
data = self.request({
|
data = self.request({
|
||||||
"path": "/forecast",
|
"path": "/forecast",
|
||||||
"query": {"q": self.build_location(location)}
|
"query": {"q": name}
|
||||||
})
|
})
|
||||||
return self.to_forecast(data, "3h")
|
return self.to_forecast(data, "3h")
|
||||||
|
|
||||||
def daily_forecast(self, location, limit=None):
|
def daily_forecast(self, name, limit=None):
|
||||||
query = {"q": self.build_location(location)}
|
query = {"q": name}
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
query["cnt"] = limit
|
query["cnt"] = limit
|
||||||
data = self.request({
|
data = self.request({
|
||||||
|
@ -135,7 +130,7 @@ class WeatherSkill(MycroftSkill):
|
||||||
def handle_current_intent(self, message):
|
def handle_current_intent(self, message):
|
||||||
try:
|
try:
|
||||||
location = message.data.get("Location", self.location)
|
location = message.data.get("Location", self.location)
|
||||||
weather = self.owm.weather_at_place(location).get_weather()
|
weather = self.owm.weather_at_place(self.__build_location(location)).get_weather()
|
||||||
data = self.__build_data_condition(location, weather)
|
data = self.__build_data_condition(location, weather)
|
||||||
weather_code = str(weather.get_weather_icon_name())
|
weather_code = str(weather.get_weather_icon_name())
|
||||||
img_code = self.CODES[weather_code]
|
img_code = self.CODES[weather_code]
|
||||||
|
@ -155,7 +150,7 @@ class WeatherSkill(MycroftSkill):
|
||||||
try:
|
try:
|
||||||
location = message.data.get("Location", self.location)
|
location = message.data.get("Location", self.location)
|
||||||
weather = self.owm.three_hours_forecast(
|
weather = self.owm.three_hours_forecast(
|
||||||
location).get_forecast().get_weathers()[0]
|
self.__build_location(location)).get_forecast().get_weathers()[0]
|
||||||
data = self.__build_data_condition(location, weather)
|
data = self.__build_data_condition(location, weather)
|
||||||
weather_code = str(weather.get_weather_icon_name())
|
weather_code = str(weather.get_weather_icon_name())
|
||||||
img_code = self.CODES[weather_code]
|
img_code = self.CODES[weather_code]
|
||||||
|
@ -173,8 +168,7 @@ class WeatherSkill(MycroftSkill):
|
||||||
def handle_next_day_intent(self, message):
|
def handle_next_day_intent(self, message):
|
||||||
try:
|
try:
|
||||||
location = message.data.get("Location", self.location)
|
location = message.data.get("Location", self.location)
|
||||||
weather = self.owm.daily_forecast(
|
weather = self.owm.daily_forecast(self.__build_location(location)).get_forecast().get_weathers()[1]
|
||||||
location).get_forecast().get_weathers()[1]
|
|
||||||
data = self.__build_data_condition(
|
data = self.__build_data_condition(
|
||||||
location, weather, 'day', 'min', 'max')
|
location, weather, 'day', 'min', 'max')
|
||||||
weather_code = str(weather.get_weather_icon_name())
|
weather_code = str(weather.get_weather_icon_name())
|
||||||
|
@ -190,11 +184,23 @@ class WeatherSkill(MycroftSkill):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("Error: {0}".format(e))
|
LOG.error("Error: {0}".format(e))
|
||||||
|
|
||||||
|
def __build_location(self, location):
|
||||||
|
try:
|
||||||
|
if type(location) is dict:
|
||||||
|
return location["city"]["name"] + ", " + location["city"]["state"]["name"] + ", " + \
|
||||||
|
location["city"]["state"]["country"]["name"]
|
||||||
|
else:
|
||||||
|
return location
|
||||||
|
except:
|
||||||
|
self.speak_dialog("location.not.found")
|
||||||
|
|
||||||
def __build_data_condition(
|
def __build_data_condition(
|
||||||
self, location, weather, temp='temp', temp_min='temp_min',
|
self, location, weather, temp='temp', temp_min='temp_min',
|
||||||
temp_max='temp_max'):
|
temp_max='temp_max'):
|
||||||
|
if type(location) is dict:
|
||||||
|
location = location["city"]["name"]
|
||||||
data = {
|
data = {
|
||||||
'location': location.get("city", {}).get("name", "Lawrence"),
|
'location': location,
|
||||||
'scale': self.temperature,
|
'scale': self.temperature,
|
||||||
'condition': weather.get_detailed_status(),
|
'condition': weather.get_detailed_status(),
|
||||||
'temp_current': self.__get_temperature(weather, temp),
|
'temp_current': self.__get_temperature(weather, temp),
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
I could not find the location
|
Loading…
Reference in New Issue