I’m trying to use open weather map to make a weather bot. I’m using the code from the demo and everything is fine except actions. I have slot location but i don’t know how to replace the q in the url with the slot.
It looks like this:
loc = tracker.get_slot('location')
current = requests.get('http://api.openweathermap.org/data/2.5/weather?q&appid=cc24cc7c42f06680e1bec75abb70ca0c').json()
My question is how do i make the q value be the slot value without using Apixu?
Okay Sir,
I fixed your problem
This is the Json format you got from api.openweather.org. It key and value pairs does not matched your previous solution. In my understanding the Apixu.weather.api is different than api.openweather.org
from rasa_sdk import Action
from rasa_sdk.events import SlotSet
import requests
class ActionWeather(Action):
def name(self):
return 'action_weather'
def run(self, dispatcher, tracker, domain):
api_key = 'cc24cc7c42f06680e1bec75abb70ca0c' #your apixu key
loc = tracker.get_slot('location')
current = requests.get('http://api.openweathermap.org/data/2.5/weather?q={}&appid=cc24cc7c42f06680e1bec75abb70ca0c'.format(loc)).json()
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)]