-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
50 lines (40 loc) · 1.67 KB
/
app.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
import requests
import json
# Text Search API
def get_place_id(google_key, headers):
hotel_name = 'HOTEL VILLA PANTHEON'
lat_lng = '48.84917,2.34615'
base_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
params = '?location=' + lat_lng + '&query=' + hotel_name + '&radius=10&key=' + google_key
url = base_url + params
response = requests.request('GET', url, headers=headers, data={})
json_response = json.loads(response.text)
place_id = json_response['results'][0]['place_id']
return place_id
# Place Details API
def place_details(google_key, headers, place_id):
url = 'https://maps.googleapis.com/maps/api/place/details/json?place_id=' + place_id + '&key=' + google_key
response = requests.request('GET', url, headers=headers, data={})
json_response = json.loads(response.text)
photo_references = []
for i in range(len(json_response['result']['photos'])):
photo_references.append(json_response['result']['photos'][i]['photo_reference']
)
return photo_references
# Place Photos API
def place_photos(google_key, photo_reference):
url = 'https://maps.googleapis.com/maps/api/place/photo?photo_reference=' + photo_reference + '&key=' + google_key
headers = {
'Accept': 'image/*'
}
response = requests.request('GET', url, headers=headers, data={})
print(response)
def main():
google_key = 'GOOGLE_API_KEY'
headers = { 'Accept': 'application/json'
}
place_id = get_place_id(google_key, headers)
photo_references = place_details(google_key, headers, place_id)
photos = place_photos(google_key, photo_references[0])
if __name__ == "__main__":
main()