-
Notifications
You must be signed in to change notification settings - Fork 1
/
actions.py
executable file
·35 lines (26 loc) · 1.15 KB
/
actions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
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)
try:
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)
except:
dispatcher.utter_message("Something went wrong. Unable to get details of the weather. Please try again!")
return [SlotSet('location',loc)]