-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle_places.py
More file actions
51 lines (37 loc) · 1.44 KB
/
google_places.py
File metadata and controls
51 lines (37 loc) · 1.44 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
from urllib.request import urlopen
class google_buss:
def __init__(self, name, address,rating,reviews):
self.name = name
self.address = address
self.rating = rating
self.reviews = reviews
google_search_url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={},{}&radius={}&types=food&key={}'
google_place_url = 'https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}'
google_api_key='AIzaSyCu2AbGho4JR_QgNVp1pw3hHebcd2xJ9Vw'
def make_request(venuesearch_url):
return json.loads(urlopen(venuesearch_url).read().decode(encoding='UTF-8'))
def search(lat, lng, distance):
gs_url = google_search_url.format(lat, lng, distance, google_api_key)
place_list = []
try:
data = make_request(gs_url)
for result in data['results']:
if 'restaurant' in result['types']:
place = search_place(result['place_id'])
place_list.append(place)
except Exception as e:
print(e)
return place_list
def search_place(place_id):
url = google_place_url.format(place_id, google_api_key)
try:
data = make_request(url)
place = data['result']
return google_buss(place['name'],
place['formatted_address'],
place['rating'],
place['reviews'],
)
except Exception as e:
print(e)