forked from rayyan35p/gowheresia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
95 lines (80 loc) · 2.83 KB
/
main.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
from flask import Flask, render_template, request
import requests
import json
# REPLACE WITH YOUR API KEY HERE, AND ONLY HERE!
MY_API_KEY = "Enter your API Key here"
API_KEY = MY_API_KEY
class Location():
API_KEY = MY_API_KEY
def __init__(self, locationid, name, distance, address):
self.locationid = locationid
self.name = name
self.distance = distance
self.address = address
def getName(self):
return self.name
def getImage(self):
API_KEY = MY_API_KEY
headers = {"accept": "application/json"}
response = requests.get(
"https://api.content.tripadvisor.com/api/v1/location/" +
self.locationid + "/photos",
headers=headers,
params={
'key': API_KEY
}).json()
try:
return response.get('data')[0].get('images').get('large').get('url')
except:
return "https://www.escapeauthority.com/wp-content/uploads/2116/11/No-image-found.jpg"
def getReviews(self):
API_KEY = MY_API_KEY
headers = {"accept": "application/json"}
response = requests.get(
"https://api.content.tripadvisor.com/api/v1/location/" +
self.locationid + "/reviews",
headers=headers,
params={
'key': API_KEY
}).json()
reviews = ""
try:
for items in response.get('data'):
reviews = reviews + items.get('text') + "\n"
return reviews
except:
return "No Reviews"
def get_points_of_interest(location):
url = 'https://api.content.tripadvisor.com/api/v1/location/search'
params = {'key': API_KEY, 'searchQuery': location}
headers = {"accept": "application/json"}
response = requests.get(url, headers=headers, params=params).json()
#put try exception in case of no results
location_id1 = response.get('data')[0].get('location_id')
response2 = requests.get(
'https://api.content.tripadvisor.com/api/v1/location/' + location_id1 +
'/details',
headers=headers,
params={
'key': API_KEY
}).json()
location_longitude = response2.get('longitude')
location_latitude = response2.get('latitude')
latLong = location_latitude + "," + location_longitude
response3 = requests.get(
'https://api.content.tripadvisor.com/api/v1/location/nearby_search',
headers=headers,
params={
'key': API_KEY,
'latLong': latLong
}).json()
list_of_locations = []
for locations in response3.get('data'):
location_id2 = locations.get('location_id')
location_name = locations.get('name')
location_distance = locations.get('distance')
location_address = locations.get('address_obj').get('address_string')
new_location = Location(location_id2, location_name, location_distance,
location_address)
list_of_locations.append(new_location)
return list_of_locations