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)
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)
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)
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"]
from chatterbot import ChatBot from chatterbot.trainers import ListTrainer,ChatterBotCorpusTrainer from flask import Flask, flash, redirect, render_template, request, session, abort, jsonify, redirect, url_for, make_response import requests import pandas as pd from pandas import json_normalize from pyzomato import Pyzomato from zomato import Zomato import json z = Zomato("21c140569818431922d7b4c833c0849e") common = z.common location = z.location restaurant = z.restaurant app = Flask(__name__) bot = ChatBot("Zoma-bot", read_only=False, logic_adapters=[ {"import_path":"chatterbot.logic.BestMatch", "default_response":"Sorry I don't understand you", "maximum_similarity_threshold": 0.9 } ]) @app.route("/") def main(): return render_template("index1.html")
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"])
def do_init(): from zomato import Zomato z = Zomato(API_KEY="21c140569818431922d7b4c833c0849e") return z
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")
from flask import Flask from flask_ask import Ask, statement, question, session from zomato import Zomato import json from unidecode import unidecode app = Flask(__name__) ask = Ask(app, "/zomato") z = Zomato("309e354eabc5cf4d7ea8eddef054c677") id=0 restaurant_names=[] details = [] cuisine = [] cost = [] rating = [] def get_categories(): data=z.parse("categories","") print data data_json= json.loads(data) l=[] for x in data_json['categories']: l.append(unidecode(x[u'categories'][u'name'])+"....") l=' '.join([i for i in l]) l = l.replace('&','and') return l def get_collections(cid): data=z.parse("collections","city_id={}".format(cid)) print data data_json= json.loads(data)
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")
""" Created on Sun May 31 17:45:29 2020 @authors: chetanrupakheti, milson """ from django.shortcuts import render import numpy as np from matplotlib import pyplot as plt from zomato import Zomato import requests import json z = Zomato("ef7a18bb9bda931d550f4965d60e5be7") # zomato obj with key common = z.common location = z.location restaurants = z.restaurant cusines_map = {} # maps cusine name to its ID def getRestaurant(id): # id = int """ Returns a restaurant's details @params id: restautant @return: json object of restaurant """ return restaurants.get_restaurant(id)
import telegram from telegram.ext import Updater, CommandHandler, MessageHandler, Filters from location import Location from zomato import Zomato TOKEN = "486717629:AAET2FKjId2ehdhUeK-UYjQqkbtW35Musds" updater = Updater(token=TOKEN) dispatcher = updater.dispatcher ##Fonksiyon l = Location() z = Zomato("ba778a4b6afff374876684ada9ddeac1") def Start(bot, update): location_keyboard = telegram.KeyboardButton(text="Konumunu Gönder", request_location=True) custom_keyboard = [[location_keyboard]] reply_markup = telegram.ReplyKeyboardMarkup(custom_keyboard) bot.sendMessage(chat_id=update.message.chat_id, text = "Size iyi kalitede hizmet vermemiz için Konumunuzu gönderiniz.", reply_markup = reply_markup) def set_location(bot, update): l.set_location(update.message.location)##setting location bot.sendMessage(chat_id=update.message.chat_id, text=l.get_location()["longitude"]) def deneme(bot, update): a = l.get_location() print(z.get_City(a["latitude"], a["longitude"])) def money_to_eat(bot,update):
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"]}]})
# 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" % (
def do_init(): from zomato import Zomato z = Zomato(API_KEY="e74778cd3728858df3578092ecea02cf") return z
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")