forked from iici-psiddineni/ML_Telecom_Churn
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactions.py
More file actions
35 lines (30 loc) · 1.23 KB
/
actions.py
File metadata and controls
35 lines (30 loc) · 1.23 KB
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.actions.action import Action
from rasa_core.events import SlotSet
import zomatopy
import json
class ActionSearchRestaurants(Action):
def name(self):
return 'action_restaurant'
def run(self, dispatcher, tracker, domain):
config={ "user_key":"6ce88a5ec1419e335afa1c7f92f4b739"}
zomato = zomatopy.initialize_app(config)
loc = tracker.get_slot('location')
cuisine = tracker.get_slot('cuisine')
location_detail=zomato.get_location(loc, 1)
d1 = json.loads(location_detail)
lat=d1["location_suggestions"][0]["latitude"]
lon=d1["location_suggestions"][0]["longitude"]
cuisines_dict={'bakery':5,'chinese':25,'cafe':30,'italian':55,'biryani':7,'north indian':50,'south indian':85}
results=zomato.restaurant_search("", lat, lon, str(cuisines_dict.get(cuisine)), 5)
d = json.loads(results)
response=""
if d['results_found'] == 0:
response= "no results"
else:
for restaurant in d['restaurants']:
response=response+ "Found "+ restaurant['restaurant']['name']+ " in "+ restaurant['restaurant']['location']['address']+"\n"
dispatcher.utter_message("-----"+response)
return [SlotSet('location',loc)]