class ZomotoAPI: def __init__(self): # Api secret keys stored in enviornment variable self.api_key = os.environ.get('api_key') def get_Categories(self, citi_id): self.api_client_auth = Pyzomato(self.api_key) self.api_client_auth.search(name="Chennai") # city id for chennai is 7 return self.api_client_auth.getCategories() def search_city_by_geo_code(self, latitude, longitude): return self.api_client_auth.getByGeocode(latitude, longitude) def locating_res_by_id(self, res_id): # id > 18387708 # name > kakada ramprasad # "locality_verbose": "Kilpauk, Chennai" return self.api_client_auth.getRestaurantDetails(res_id)
def search(request): p = Pyzomato('') list = [] try: searchCategory = request.GET.get('searchCategory','') searchKeyWord = request.GET.get('searchKeyWord','') response='' if searchCategory == 'cuisines': cuisine_id = '' cusineResponse = p.getCuisines(city_id = '4') for num, cuisine in enumerate(cusineResponse['cuisines']): if cuisine['cuisine']['cuisine_name'] == searchKeyWord: cuisine_id = cuisine['cuisine']['cuisine_id'] response = p.search(entity_type="city", entity_id='4',cuisines=cuisine_id) if searchCategory == 'restaurantType': restaurantTypeValue = '' restaurantTypeResponse = p.getEstablishments(city_id = '4') for num, establishment in enumerate(restaurantTypeResponse['establishments']): if establishment['establishment']['name'] == searchKeyWord: restaurantTypeValue = establishment['establishment']['id'] response = p.search(entity_type="city", entity_id='4', establishment_type=restaurantTypeValue) if searchCategory == 'restaurantCategory': category_id = '' category_response = p.getCategories() for num, category in enumerate(category_response['categories']): if category['categories']['name'] == searchKeyWord: category_id = category['categories']['id'] response = p.search(entity_type="city", entity_id='4', category=category_id) except Exception as e: print(e) try: for num, restaurant in enumerate(response['restaurants']): number= num+1, name=restaurant['restaurant']['name'] name = name.format() url=restaurant['restaurant']['url'] cuisines=restaurant['restaurant']['cuisines'] rating=restaurant['restaurant']['user_rating']['aggregate_rating'] icon=restaurant['restaurant']['thumb'] price=restaurant['restaurant']['average_cost_for_two'] res_id=restaurant['restaurant']['id'] dictlist = [dict() for x in range(9)] dictlist={'number':number, 'name':name, 'url':url, 'cuisines':cuisines, 'rating':rating, 'icon':icon, 'price':price, 'res_id':res_id } list.append(dictlist) except Exception as e: print(e) return render(request, 'home.html', {'context': list})
#Oleksandr Bihary #Using Zomato API we obtain resturants names in the Las Vegas area and their Reviews #API KEY: aa2e170fced5e4de42b96789a76fbd7f import pprint from pyzomato import Pyzomato pp = pprint.PrettyPrinter(indent=2) p = Pyzomato("aa2e170fced5e4de42b96789a76fbd7f") p.search(q="las vegas") categories = p.getCategories() pp.pprint( categories ) dets = p.getCollectionsViaCityId(282) pp.pprint( dets ) cus = p.getCuisines(282) pp.pprint( cus ) estab = p.getEstablishments(282) pp.pprint( estab ) #need resturant ID menu = p.getDailyMenu(292) pp.pprint( menu ) #need resturant ID info = p.getRestaurantDetails(292) pp.pprint( info )
from pyzomato import Pyzomato p = Pyzomato(adb186fd589334b4ddda0aa4b2c8fc03) p.search(q="london") p.getCategories()
# Zomato API configure from pyzomato import Pyzomato # Initialise Zomato Object zomato = Pyzomato(os.getenv('ZOMATO_API_KEY')) # Open JSON file from dir # Table source: https://wiki.openstreetmap.org/wiki/List_of_London_Underground_stations stations = pd.read_json(os.path.join(os.getcwd(), 'home/tube_stations.json')) # Get Lat, Lng & Name stations = stations.iloc[:, [2, 4, 5]] # Get categories categories = zomato.getCategories() categories = [[r['categories']['id'], r['categories']['name']] for r in categories['categories'] if r['categories']['name'] in ['Cafes', 'Breakfast', 'Lunch', 'Dinner', 'Pubs & Bars']] # VueJs json files # Categories as json categories_json = {} for i in range(0, len(categories)): categories_json[categories[i][1]] = categories[i][0] categories_json = j.dumps(categories_json, ensure_ascii=True) # Stations as json stations_json = {} for i in range(0, len(stations.index)):