This repository has been archived by the owner on Sep 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
google.py
55 lines (39 loc) · 1.4 KB
/
google.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
from api_keys import GOOGLE_API_KEY
from business import Business, make_request
SEARCH_URL = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={},{}&radius={}&types=bar&key={}'
PLACE_URL = 'https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}'
def search(lat, lng, distance):
"""
Searches the Google Places API (Max Limit = 20)
:param lat: Latitude of the request
:param long: Longitude of the request
:param distance: Distance to search (meters)
:returns: List of retrieved places
"""
url = SEARCH_URL.format(lat, lng, distance, GOOGLE_API_KEY)
place_list = []
try:
data = make_request(url)
for result in data['results']:
place = search_place(result['place_id'])
place_list.append(place)
except Exception, e:
print e
return place_list
def search_place(place_id):
"""
Searches Google for a specific Place
:param id: Google Place ID
:returns: Business object
"""
url = PLACE_URL.format(place_id, GOOGLE_API_KEY)
try:
data = make_request(url)
place = data['result']
return Business(place['name'],
place['formatted_address'].split(',')[0],
place['rating'],
place['user_ratings_total'],
'N/A')
except Exception, e:
print e