-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_get.py
55 lines (40 loc) · 1.78 KB
/
web_get.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
import requests
from geopy.geocoders import Nominatim
import json
def web_get_hotel(address):
geolocator = Nominatim()
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
request_url = "http://api.tripadvisor.com/api/partner/2.0/map/{},{}/hotels?limit=20&offset=0%22&key=33b67ced-8002-4c51-a43b-ab2faa5e843e".format(latitude, longitude)
# print (request_url)
response = requests.get(request_url)
data = json.loads(response.text)
return data
def web_get_restaurant(address):
geolocator = Nominatim()
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
request_url = "http://api.tripadvisor.com/api/partner/2.0/map/{},{}/restaurants?limit=20&offset=0%22&key=33b67ced-8002-4c51-a43b-ab2faa5e843e".format(latitude, longitude)
response = requests.get(request_url)
data = json.loads(response.text)
return data
def web_get_attraction(address):
geolocator = Nominatim()
location = geolocator.geocode(address)
latitude = location.latitude
longitude = location.longitude
request_url = "http://api.tripadvisor.com/api/partner/2.0/map/{},{}/attractions?limit=20&offset=0%22&key=33b67ced-8002-4c51-a43b-ab2faa5e843e".format(latitude, longitude)
response = requests.get(request_url)
data = json.loads(response.text)
return data
if __name__ == "__main__":
geolocator = Nominatim()
#location = geolocator.geocode(address)
#print((location.latitude, location.longitude))
x = web_get(address)
data = json.loads('{}'.format(x.text))
# pprint(data)
city = data["data"][0]["address_obj"]["city"]
country = data["data"][0]["address_obj"]["country"]