コード例 #1
0
ファイル: app.py プロジェクト: JainVikas/Zomato_fb_chatbot
def collection():
    z = Zomato("ZOMATO-API-KEY")
    collection_id = request.args.get('collection_id')
    print(request.query_string)
    output ={"messages": [{ "attachment":{"type":"template", "payload":{"template_type":"generic","elements":[]}}}]}
    testing_output = z.parse("search","lat="+str(session["latitude"]) + ","+ "lon="+str(session["longitude"]) + ","+"collection_id="+str(collection_id))
    k = 8
    if testing_output["results_found"]<8:
        k = testing_output["results_found"]
    for i in range(k):
	#len(testing_output["collections"])):
        restaurant_dict={}
        button=[]
        button_dict={}
        button_dict["type"]="show_block"
        button_dict["block_name"]= "restaurant" 
        button_dict["set_attributes"] = {"res_id": testing_output["restaurants"][i]["restaurant"]["id"]} 
        button_dict["title"]= "Check Reviews"
        button.append(button_dict)
        restaurant_dict["title"] = testing_output["restaurants"][i]["restaurant"]["name"]
        restaurant_dict["subtitle"] = "Average cost for 2: " + str(testing_output["restaurants"][i]["restaurant"]["average_cost_for_two"])
        restaurant_dict["image_url"] = testing_output["restaurants"][i]["restaurant"]["featured_image"]
        restaurant_dict["buttons"] = button 
        output["messages"][0]["attachment"]["payload"]["elements"].append(restaurant_dict)
    return jsonify(output)
コード例 #2
0
ファイル: app.py プロジェクト: JainVikas/Zomato_fb_chatbot
def restaurant():
    z = Zomato("ZOMATO-API-KEY")
    res_id = request.args.get('res_id')
    print(request.query_string)
    output ={"messages": [{ "attachment":{"type":"template", "payload":{"template_type":"generic","elements":[]}}}]}
    testing_output = z.parse("reviews","res_id="+str(res_id))
    for i in range(testing_output["reviews_shown"]):
	#len(testing_output["collections"])):
        review_dict={}
        #button=[]
        #button_dict={}
        #button_dict["type"]="show_block"
        ##button_dict["block_name"]= "restaurant" 
        #button_dict["set_attributes"] = {"res_id": testing_output["restaurants"][i]["restaurant"]["id"]} 
        #button_dict["title"]= "Check Reviews"
        #button.append(button_dict)
        review_dict["title"] = "Rating: " + str(testing_output["user_reviews"][i]["review"]["rating"])
        review_dict["subtitle"] = testing_output["user_reviews"][i]["review"]["review_text"]
        review_dict["image_url"] = ""
        
        #restaurant_dict["buttons"] = button 
        output["messages"][0]["attachment"]["payload"]["elements"].append(review_dict)
    output["redirect_to_blocks"] = ["call"]
    #output["messages"][0]["attachment"]["payload"]["buttons"]=[{"type":"phone_number", "phone_number": "+919538668889","title": "Call to reserve"},{"type":"show_block", "block_name":"restaurant","title":"Try another"}]
    print(output)
    return jsonify(output)
コード例 #3
0
ファイル: app.py プロジェクト: JainVikas/Zomato_fb_chatbot
def webhook_viaFB():
    z = Zomato("ZOMATO-API-KEY")
    query_string = request.query_string
    if request.args.get('latitude') is not None:
        session["latitude"] = request.args.get('latitude')
    if request.args.get('longitude') is not None:
        session["longitude"]= request.args.get('longitude')
    category = request.args.get('text')
    cuisine = request.args.get('cuisine')
    #print(cuisine)
    #print(longitude)
    #print(latitude)
    #print(query_string)
    output ={"messages": [{ "attachment":{"type":"template", "payload":{"template_type":"generic","elements":[]}}}]}
    testing_output = z.parse("collections","lat="+str(session["latitude"]) + ","+ "lon="+str(session["longitude"]))
    #output of parse is a dict, so quite convinient to find details using inbuit features of python dict
    for i in range(9):
    #len(testing_output["collections"])):
        collection_dict={}
        button=[]
        button_dict={}
        button_dict["type"]="show_block"
        button_dict["block_name"]= "collection" 
        button_dict["set_attributes"] = {"collection_id": testing_output["collections"][i]["collection"]["collection_id"]} 
        button_dict["title"]= "Explore"
        button.append(button_dict)
        collection_dict["title"] = testing_output["collections"][i]["collection"]["title"]
        collection_dict["subtitle"] = testing_output["collections"][i]["collection"]["description"]
        collection_dict["image_url"] = testing_output["collections"][i]["collection"]["image_url"]
        collection_dict["buttons"] = button 
        output["messages"][0]["attachment"]["payload"]["elements"].append(collection_dict)
    return jsonify(output)   	
コード例 #4
0
def queryAccept(query):

    #Variable Declaration
    searchLat = ""
    searchLon = ""
    cuisineType = ""
    priceLevel = ""
    searchDistance = "1"

    for key in query:
        if key == "lat":
            searchLat = str(query["lat"])
        elif key == "lon":
            searchLon = str(query["lon"])
        elif key == "cuisine":
            cuisineType = cuisineTranslate(query["cuisine"])
        elif key == "price":
            priceLevel = str(query["price"])
        elif key == "distance":
            if query["distance"] == "20+":
                searchDistance = str(24 * 1609)
            else:
                searchDistance = str(int(query["distance"]) * 1609)
        elif key == "time":
            '''
                  distanceRef = {"1":1, "5":5, "10":10, "15":15, "20":20, "20+":24}
                  searchLat = str(lat)
                  searchLon = str(lon)
                  cuisineType = cuisineTranslate(cuisine) #check against array and convert to numerical value
                  searchdistance = str(distance * 1609) #distance will be in km, Zomato api needs in meters
                  #creates query needed for Zomato
            '''
    restQuery = "lat=" + searchLat + ", lon=" + searchLon + ", radius =" + searchDistance + ", cuisines=" + cuisineType
    restKey = Zomato(APIKEY[-1])
    restJSON = restKey.parse("search", restQuery)
    if not restJSON:
        return None
    return restJSON["restaurants"]
コード例 #5
0
from zomato import Zomato
import json

z = Zomato("309e354eabc5cf4d7ea8eddef054c677")
# A call to categories endpoint from zomato API.

# A call to restaurants endppoint from zomato 
# API with required parameters res_id
#z.parse("restaurant","res_id=16774318")


data=z.parse("locations","query=mumbai")
print data
data_json= json.loads(data)

l=[]
for x in data_json["location_suggestions"]:
	id = x[u'entity_id']
	type = x[u'entity_type']
print type
print "entity_id={}".format(id)
data = z.parse("location_details","entity_id={}".format(id)+","+"entity_type={}".format(type))
data=json.loads(data)

l=[]
for i in range(10):
	if data["best_rated_restaurant"][i]["restaurant"]["name"]:
		l.append(data["best_rated_restaurant"][i]["restaurant"]["name"])
コード例 #6
0
ファイル: test.py プロジェクト: JainVikas/Zomato_fb_chatbot
from zomato import Zomato

z = Zomato("ZOMATO-API-KEY")
# A call to categories endpoint from zomato API.
z.parse("categories", "")
# A call to restaurants endppoint from zomato
# API with required parameters res_id
z.parse("restaurant", "res_id=16774318")
コード例 #7
0
ファイル: test.py プロジェクト: VikramjitRoy/Zomato-Python
from zomato import Zomato
z = Zomato("ZOMATO-API-KEY")
# A call to categories endpoint from zomato API.
z.parse("categories","")
# A call to restaurants endppoint from zomato 
# API with required parameters res_id
z.parse("restaurant","res_id=16774318")
コード例 #8
0
ファイル: app.py プロジェクト: JainVikas/Zomato_fb_chatbot
def webhook_manually():
    z = Zomato("ZOMATO-API-KEY")
    testing_output = z.parse("restaurant","res_id=16774318")
    #output of parse is a dict, so quite convinient to find details using inbuit features of python dict
    
    return jsonify({"messages": [{"text": "How can I help you?"}, {"text": "your api key is"+testing_output["apikey"]}]})    
コード例 #9
0
# Creation of Database and table if alreay created then hash the codes
db = MySQLdb.connect(
    host="localhost",
    user="******",  # your host, usually localhost
    passwd="ankiosa#084507")  # your password
cursor = db.cursor()
sql = 'CREATE DATABASE zomato_restaurant_review_sentiment'
cursor.execute(sql)
sql = 'USE zomato_restaurant_review_sentiment'
cursor.execute(sql)
sql = 'CREATE TABLE restaurant_sentiment_16774318 (review_id VARCHAR(13),user_name VARCHAR(50),user_profile VARCHAR(50), rating VARCHAR(4),review_text VARCHAR(500), timestam VARCHAR(12),review_sent VARCHAR(3))'
cursor.execute(sql)

#Extracting Reviews from particular restaurant
z = Zomato("66ae423d7084dab625ce29bdcdba3b28")
output = z.parse("reviews", "res_id=16673760")  #16774318") #16673760
output_json = json.loads(output)

#Checking if it exists in MYSQL Database or not
# Deleting is done to remove 3 of the reviews to show how its work
for delete_count in range(3):
    review_id = output_json['user_reviews'][delete_count]['review']['id']
    query = "DELETE FROM restaurant_sentiment_16774318 WHERE review_id = %s"
    cursor.execute(query, (review_id, ))
    db.commit()

for review_count in range(5):
    review_id = output_json['user_reviews'][review_count]['review']['id']
    review_ids = str(review_id)
    sqlq = "SELECT COUNT(1) FROM restaurant_sentiment_16774318 WHERE review_id = %s" % (
        review_ids)
コード例 #10
0
ファイル: test.py プロジェクト: YashSheth1/Zomato-
from zomato import Zomato
z = Zomato("6833acc57f2a5d311450865c59d3b7f2")
# A call to categories endpoint from zomato API.
#z.parse("categories","")
# A call to restaurants endppoint from zomato 
# API with required parameters res_id
#z.parse("restaurant","res_id=16774318")
#cities={"Mumbai":{"lat":19.0176,"log":72.856}}
z.parse("search","lat=19.0176,lon=72.856")
z.parse("search","lat=17.366,lon=78.476")
z.parse("search","lat=28.625789,lon=77.210276")
z.parse("search","lat=13.083889,lon=80.27")