Open jmourato opened 5 years ago
@jmourato Nice! Would you be up for creating a PR for this? :)
Hi Justina
I'll do a pull request for this issue, np
Hi @JustinaPetr
Just made a PR with the changes.
Regards João
Thanks for the commend...this works perfectly!
from future import absolute_import from future import division from future import unicode_literals
from rasa_core.actions.action import Action from rasa_core.events import SlotSet
class ActionWeather(Action): def name(self): return 'action_weather'
def run(self, dispatcher, tracker, domain):
from apixu.client import ApixuClient
api_key = '................................' #your apixu key
client = ApixuClient(api_key)
loc = tracker.get_slot('location')
current = client.current(q=loc)
country = current['location']['country']
city = current['location']['name']
condition = current['current']['condition']['text']
temperature_c = current['current']['temp_c']
humidity = current['current']['humidity']
wind_mph = current['current']['wind_mph']
response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)
dispatcher.utter_message(response)
return [SlotSet('location',loc)]
use below as actions.py
from future import absolute_import from future import division from future import unicode_literals
from rasa_core_sdk import Action from rasa_core_sdk.events import SlotSet import requests
class ActionWeather(Action): def name(self): return 'action_weather'
def run(self, dispatcher, tracker, domain):
from apixu.client import ApixuClient
api_key = '###########' #your apixu key
client = ApixuClient(api_key)
loc = tracker.get_slot('location')
params = {
'access_key': api_key,
'query': str(loc)
}
print("Searching in location ", loc)
api_result = requests.get('http://api.weatherstack.com/current', params)
current= api_result.json()
print ('res ', current)
country = current['location']['country']
city = current['location']['name']
condition = current['current']['weather_descriptions']
temperature_c = current['current']['temperature']
humidity = current['current']['humidity']
wind_mph = current['current']['wind_speed']
response = """It is currently {} in {} at the moment. The temperature is {} degrees, the humidity is {}% and the wind speed is {} mph.""".format(condition, city, temperature_c, humidity, wind_mph)
dispatcher.utter_message(response)
return [SlotSet('location',loc)]
Yeah please check, i just tested few minutes ago, with Free Account. It only support http request
Hi gurtajs4
Works well, although as I installed it from scratch I had to change the config file as I was getting some errors.
client.getCurrentWeather(q=loc) (in actions.py line 33) fails as apixu has changed the api.
Solve this issue by replacing client.getCurrentWeather(q=loc) with
current = client.current(q=loc) to run according to the current code in https://github.com/apixu/apixu-python
check https://github.com/apixu/apixu-python/blob/master/apixu/client.py line 46 ... def current(self, q=None): ....