def get_best_hotel(city, date_in, date_out): hotels_service = Hotels('prtl6749387986743898559646983194') city = city_string_to_id_for_hotels(city) resp = hotels_service.get_result( **{ 'market': 'ES', 'currency': 'EUR', 'locale': 'en-GB', 'country': 'ES', 'entityid': city['individual_id'], 'checkindate': date_in, 'checkoutdate': date_out, 'guests': 1, 'rooms': 1 }) hotels_prices = dict([(hotel['id'], hotel) for hotel in resp.json()['hotels_prices']]) hotels = sorted(resp.json()['hotels'], key=lambda x: x['popularity']) for hotel in hotels: hotel['price'] = hotels_prices[ hotel['hotel_id']]['agent_prices'][0]['price_total'] if not hotels: return {} the_hotel_offer = random.choice(hotels[:5]) return { 'type': 'hotel', 'date': date_out, 'price': str(int(the_hotel_offer['price'])), # 'details': { # 'latitude': the_hotel_offer['latitude'], # 'longitude': the_hotel_offer['longitude'], # 'name': the_hotel_offer['name'], # 'checkin': date_in, # 'checkout': date_out # } 'description': "In %s, stay at %s, until %s" % (city['display_name'], the_hotel_offer['name'], parser.parse(date_out).strftime("%B %d, %Y, %A")), 'detailsLink': '#', 'img': '' }
def test_get_result_xml(self): """ http://partners.api.skyscanner.net/apiservices/carhire/liveprices/v2/{market}/{currency}/{locale}/{pickupplace}/{dropoffplace}/{pickupdatetime}/{dropoffdatetime}/{driverage}?apiKey={apiKey}&userip={userip} YYYY-MM-DDThh:mm """ hotels_service = Hotels(self.api_key, response_format='xml') self.result = hotels_service.get_result(market='DE', currency='EUR', locale='de-DE', entityid=27543923, checkindate=self.checkin, checkoutdate=self.checkout, guests=1, rooms=1).parsed self.assertTrue(None != self.result.find('./Hotels')) self.assertTrue(len(self.result.findall('./Hotels/HotelDto')) > 0)
def test_get_result_json(self): """ http://partners.api.skyscanner.net/apiservices/carhire/liveprices/v2/{market}/{currency}/{locale}/{pickupplace}/{dropoffplace}/{pickupdatetime}/{dropoffdatetime}/{driverage}?apiKey={apiKey}&userip={userip} YYYY-MM-DDThh:mm """ hotels_service = Hotels(self.api_key, response_format='json') self.result = hotels_service.get_result(market='UK', currency='GBP', locale='en-GB', entityid=27543923, checkindate=self.checkin, checkoutdate=self.checkout, guests=1, rooms=1).parsed self.assertTrue('hotels' in self.result) self.assertTrue(len(self.result['hotels']) > 0)
def test_get_result_xml(self): """ http://partners.api.skyscanner.net/apiservices/carhire/liveprices/v2/{market}/{currency}/{locale}/{pickupplace}/{dropoffplace}/{pickupdatetime}/{dropoffdatetime}/{driverage}?apiKey={apiKey}&userip={userip} YYYY-MM-DDThh:mm """ hotels_service = Hotels(self.api_key, response_format='xml') self.result = hotels_service.get_result( market='DE', currency='EUR', locale='de-DE', entityid=27543923, checkindate=self.checkin, checkoutdate=self.checkout, guests=1, rooms=1).parsed self.assertIsNotNone(self.result.find('./Hotels')) self.assertTrue(len(self.result.findall('./Hotels/HotelDto')) > 0)
def test_get_result_json(self): """ http://partners.api.skyscanner.net/apiservices/carhire/liveprices/v2/{market}/{currency}/{locale}/{pickupplace}/{dropoffplace}/{pickupdatetime}/{dropoffdatetime}/{driverage}?apiKey={apiKey}&userip={userip} YYYY-MM-DDThh:mm """ hotels_service = Hotels(self.api_key, response_format='json') self.result = hotels_service.get_result( market='UK', currency='GBP', locale='en-GB', entityid=27543923, checkindate=self.checkin, checkoutdate=self.checkout, guests=1, rooms=1).parsed self.assertTrue('hotels' in self.result) self.assertTrue(len(self.result['hotels']) > 0)