Skip to content

Commit

Permalink
add hotel address
Browse files Browse the repository at this point in the history
  • Loading branch information
tsolakoua committed Jan 31, 2023
1 parent 407a2eb commit 8072096
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
14 changes: 0 additions & 14 deletions amadeus_demo/map/hotel.py

This file was deleted.

17 changes: 15 additions & 2 deletions amadeus_demo/map/hotel_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
class Hotel_list:
import geocoder

class HotelList:

def __init__(self, hotel_list):
self.hotel_list = hotel_list

Expand All @@ -8,7 +11,17 @@ def construct_hotel_list(self):
list_offer['name'] = self.hotel_list['name']
list_offer['latitude'] = self.hotel_list['geoCode']['latitude']
list_offer['longitude'] = self.hotel_list['geoCode']['longitude']
# offer['address'] = self.hotel_list['address']
address = geocoder.osm(
[list_offer['latitude'], list_offer['longitude']],
method='reverse'
)
if address.json.get('houseNumber') is not None:
list_offer['address'] = address.json['street'] + ' ' + address.json['houseNumber']
elif address.json.get('housenumber') is not None:
list_offer['address'] = address.json['street'] + ' ' + address.json['housenumber']
else:
list_offer['address'] = address.json['street']

except (TypeError, AttributeError, KeyError):
pass
return list_offer
5 changes: 3 additions & 2 deletions amadeus_demo/map/templates/map/map.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ <h2>Find the perfect hotel for your journey!</h2>
var safety = JSON.parse(data);
var hotel_name = evt.target.getData();
var bubble = new H.ui.InfoBubble(evt.target.getGeometry(), {
content: hotel_name + '<div>' + safety + '</div>' + hotel_lat + ' ' +hotel_lng
content: hotel_name + '<div>' + safety + '</div>'
});
ui.addBubble(bubble);
},
Expand All @@ -78,11 +78,12 @@ <h2>Find the perfect hotel for your journey!</h2>
hotel_name = hotels[i]['name'];
hotel_lat = hotels[i]['latitude'];
hotel_lng = hotels[i]['longitude'];
hotel_address = hotels[i]['address']
addMarkerToGroup(group, {
lat: hotel_lat,
lng: hotel_lng
},
'<div style="color:blue;">' + hotel_name + '</div>' + hotel_lat +' '+ hotel_lng
'<div style="color:blue;">' + hotel_name + '</div>' + hotel_address
);
} catch (error) {
console.log(error);
Expand Down
17 changes: 3 additions & 14 deletions amadeus_demo/map/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from django.contrib import messages
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
# from .hotel import Hotel
from .hotel_list import Hotel_list
from .hotel_list import HotelList
from .point_of_interest import PointOfInterest
from .safety import Safety
from .activity import Activity
Expand All @@ -18,18 +17,16 @@ def hotels_map(request):
hotels = search_hotels('SFO')
HERE_API_KEY = os.environ.get('HERE_API_KEY')
return render(request, 'map/map.html', {'hotels': json.dumps(hotels),
'here_api_key': HERE_API_KEY
'here_api_key': 'HERE_API_KEY'
})


def search_hotels(city_code):
hotels = amadeus.reference_data.locations.hotels.by_city.get(cityCode=city_code)
hotel_offers = []
for hotel in hotels.data:
# print(hotel)
list_offer = Hotel_list(hotel).construct_hotel_list()
list_offer = HotelList(hotel).construct_hotel_list()
hotel_offers.append(list_offer)
print(hotel_offers)
return hotel_offers


Expand Down Expand Up @@ -59,15 +56,7 @@ def search_safety(request):
safety = amadeus.safety.safety_rated_locations.get(latitude=request.POST.get('hotel_lat'),
longitude=request.POST.get('hotel_lng'),
radius=2).data
# safety = amadeus.get('/v1/safety/safety-rated-locations',
# latitude=request.POST.get('hotel_lat'),
# longitude=request.POST.get('hotel_lng'),
# radius=2).data
print(request.POST.get('hotel_lat'))
print(request.POST.get('hotel_lng'))
print(safety)
safety_returned.append(Safety(safety).construct_safety_scores())
print (safety_returned)
except ResponseError as error:
messages.add_message(request, messages.ERROR, error)
return HttpResponse(json.dumps(safety_returned))
Expand Down
14 changes: 12 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
amadeus==7.0.0
amadeus==8.0.0
certifi==2022.12.7
charset-normalizer==3.0.1
click==8.1.3
decorator==5.1.1
Django==2.2.28
future==0.18.3
geocoder==1.38.1
gunicorn==20.0.4
idna==3.4
isodate==0.6.0
pycodestyle==2.5.0
pytz==2019.3
ratelim==0.1.6
requests==2.28.2
six==1.13.0
sqlparse==0.3.0
whitenoise==5.0.1
urllib3==1.26.14
whitenoise==5.0.1

0 comments on commit 8072096

Please sign in to comment.