-
Notifications
You must be signed in to change notification settings - Fork 0
/
zomato.py
99 lines (84 loc) · 3.27 KB
/
zomato.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pyzomato import Pyzomato
import os
p = Pyzomato('d67aae36be44be5d4483e0546ff03360')
cuisine_list = []
latitude = 40
longitude = -73
def get_cuisines(location=None):
global latitude, longitude
latitude = location['latitude']
longitude = location['longitude']
geocode = p.getByGeocode(latitude, longitude)
city_id = geocode['location']['city_id']
nearby_cuisines = geocode['popularity']['top_cuisines']
cuisines_dict = p.getCuisines(city_id)
global cuisine_list
for i in range(len(cuisines_dict['cuisines'])):
cuisine_list.append(cuisines_dict['cuisines'][i]['cuisine'])
return nearby_cuisines
def get_values(result, lat, long, title, address):
l = result['results_shown']
for i in range(0, l):
if result['restaurants'][i]['restaurant']['name'] not in title and len(lat) < 5:
lat.append(result['restaurants'][i]['restaurant']['location']['latitude'])
long.append(result['restaurants'][i]['restaurant']['location']['longitude'])
address.append(result['restaurants'][i]['restaurant']['location']['address'])
title.append(result['restaurants'][i]['restaurant']['name'])
def get_values_price(result, lat, long, title, address, price):
l = result['results_shown']
for i in range(0, l):
if result['restaurants'][i]['restaurant']['price_range'] == price and len(lat) < 5 and \
result['restaurants'][i]['restaurant']['name'] not in title:
lat.append(result['restaurants'][i]['restaurant']['location']['latitude'])
long.append(result['restaurants'][i]['restaurant']['location']['longitude'])
address.append(result['restaurants'][i]['restaurant']['location']['address'])
title.append(result['restaurants'][i]['restaurant']['name'])
def search_by_cuisine(cuisine):
cuisine = cuisine.title()
# print(cuisine)
cuisine_loc = (next((item for item in cuisine_list if item['cuisine_name'] == cuisine), False))
if not cuisine_loc:
return None, None, None, None
cuisine_id = cuisine_loc['cuisine_id']
result = p.search(lat=latitude, lon=longitude, radius='15000', sort='real_distance', order='asc',
cuisines=cuisine_id, count='1')
#print(result)
lat = []
long = []
address = []
title = []
get_values(result, lat, long, title, address)
print(lat)
print(long)
print(title)
print(address)
return lat, long, title, address
def search_by_price(price):
result = p.search(lat=latitude, lon=longitude, radius='20000', sort='rating', order='desc', count='20')
#print(result)
lat = []
long = []
address = []
title = []
get_values_price(result, lat, long, title, address, price)
print(lat)
print(long)
print(title)
print(address)
return lat, long, title, address
def search_by_query(query):
result = p.search(lat=latitude, lon=longitude, radius='15000', sort='real_distance', order='asc',
q=query, count='20')
#print(result)
lat = []
long = []
address = []
title = []
get_values(result, lat, long, title, address)
print(lat)
print(long)
print(title)
print(address)
return lat, long, title, address