diff --git a/amadeus_demo/map/hotel.py b/amadeus_demo/map/hotel.py deleted file mode 100644 index 634c128..0000000 --- a/amadeus_demo/map/hotel.py +++ /dev/null @@ -1,14 +0,0 @@ -class Hotel: - def __init__(self, hotel): - self.hotel = hotel - - def construct_hotel(self): - try: - offer = {} - offer['name'] = self.hotel['hotel']['name'] - offer['latitude'] = self.hotel['hotel']['latitude'] - offer['longitude'] = self.hotel['hotel']['longitude'] - offer['address'] = self.hotel['hotel']['address']['lines'] - except (TypeError, AttributeError, KeyError): - pass - return offer diff --git a/amadeus_demo/map/hotel_list.py b/amadeus_demo/map/hotel_list.py index 23c4df4..990ed7a 100644 --- a/amadeus_demo/map/hotel_list.py +++ b/amadeus_demo/map/hotel_list.py @@ -1,4 +1,7 @@ -class Hotel_list: +import geocoder + +class HotelList: + def __init__(self, hotel_list): self.hotel_list = hotel_list @@ -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 diff --git a/amadeus_demo/map/templates/map/map.html b/amadeus_demo/map/templates/map/map.html index f33f230..eb9a9ff 100644 --- a/amadeus_demo/map/templates/map/map.html +++ b/amadeus_demo/map/templates/map/map.html @@ -59,7 +59,7 @@

Find the perfect hotel for your journey!

var safety = JSON.parse(data); var hotel_name = evt.target.getData(); var bubble = new H.ui.InfoBubble(evt.target.getGeometry(), { - content: hotel_name + '
' + safety + '
' + hotel_lat + ' ' +hotel_lng + content: hotel_name + '
' + safety + '
' }); ui.addBubble(bubble); }, @@ -78,11 +78,12 @@

Find the perfect hotel for your journey!

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 }, - '
' + hotel_name + '
' + hotel_lat +' '+ hotel_lng + '
' + hotel_name + '
' + hotel_address ); } catch (error) { console.log(error); diff --git a/amadeus_demo/map/views.py b/amadeus_demo/map/views.py index 0d42cd9..ff24fb9 100644 --- a/amadeus_demo/map/views.py +++ b/amadeus_demo/map/views.py @@ -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 @@ -18,7 +17,7 @@ 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' }) @@ -26,10 +25,8 @@ 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 @@ -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)) diff --git a/requirements.txt b/requirements.txt index e11f2c8..6f30d24 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file +urllib3==1.26.14 +whitenoise==5.0.1