Friday, December 27, 2024
Google search engine
HomeLanguagesPython | Find Hotel Prices using Hotel price comparison API

Python | Find Hotel Prices using Hotel price comparison API

Makcorps hotel API is used to get JSON data, to compare Hotel prices, ratings, and reviews from more than 200 websites including; Agoda.com, Hotels.com, Expedia and more. It is organized around GET Requests. One can use this API for free to get information for any hotel or any city regarding prices, ratings, reviews, historical prices and many other things.

To use this API, one must need the API key, which can be get form here

Note: User need to create an account on makcorps.com then only can use the APIs.

Modules Needed :

requests

pip install requests

Implementation

This API will search according to the city name. Let’s suppose if a city London is searched, then output JSON will be a price comparison of different hotels in that city from different vendors along with their name. According to the vendor’s price best price will also be shown.

Below is the implementation :




# Python program to find live hotel prices  
# Python program to find live hotel prices
# status using Makcorps Hotel API
  
# import required modules
import requests, json
  
# base_url variable to store url
  
# enter city name here
city = "london"
  
# complete_url variable to
# store complete url address
complete_url = base_url + city
  
# Declaring headers needed
headers = {
    'Authorization': 'JWT your_API_id',
}
  
# get method of requests module
# return response object
response_ob = requests.get(complete_url, headers=headers)
  
# json method of response object convert
# json format data into python format data
result = response_ob.json()
  
# Now check the value of status_code is equal
# to "200" or not, if equal that means record is
# found otherwise record is not found
if response_ob.status_code == 200:
  
    #  name is extracting from
    # the result variable data
    print("price comparison data for a random date of city london is:")
    print(result)
else:
    print("record is not found for given request")


Output:

price comparison data for a random date of city london is:
{'comparison':
  [
    {
     'vendor1-price': 'US$217',
     'vendor3-price': 'US$246',
     'vendor2-price': 'US$217',
     'vendor3': 'travelup.com',
     'vendor1': 'Travelocity',
     'Hotel': 'Park Plaza Westminster Bridge London',
     'Best-price': 'US$\xa0246US$\xa0215Booking.com',
     'vendor2': 'Orbitz.com'
    }, 

    {
     'vendor1-price': '',
     'vendor3-price': '',
     'vendor2-price': '',
     'vendor3': 'Travelocity',
     'vendor1': 'Expedia.com',
     'Hotel': 'Travelodge London Covent Garden',
     'Best-price': 'US$\xa074Travelodge',
     'vendor2': 'Hotels.com'
    }, 

    {
     'vendor1-price': 'US$167',
     'vendor3-price': 'US$183',
     'vendor2-price': 'US$171',
     'vendor3': 'Nustay.com', 
     'vendor1': 'ParkGrandLondon',
     'Hotel': 'Park Grand London Kensington',
     'Best-price': 'US$\xa0170Booking.com', 
     'vendor2': 'Travelocity'
    }, 

    {
     'vendor1-price': '',
     'vendor3-price': '',
     'vendor2-price': '',
     'vendor3': 'Orbitz.com',
     'vendor1': 'Expedia.com',
     'Hotel': 'Travelodge London City hotel',
     'Best-price': 'US$\xa056Travelodge',
     'vendor2': 'Nustay.com'
    }, 

    {
     'vendor1-price': 'US$205',
     'vendor3-price': 'US$232',
     'vendor2-price': 'US$185',
     'vendor3': 'ZenHotels.com', 
     'vendor1': 'Booking.com',
     'Hotel': 'The Tower Hotel',
     'Best-price': 'US$\xa0206Orbitz.com',
     'vendor2': 'Trip.com'
    },

    {
     'vendor1-price': 'US$77',
     'vendor3-price': 'US$94',
     'vendor2-price': 'US$87',
     'vendor3': 'Nustay.com', 
     'vendor1': 'Official Site',
     'Hotel': 'Point A Hotel, London Kings Cross St Pancras',
     'Best-price': 'US$\xa087Orbitz.com',
     'vendor2': 'Booking.com'
    },

    {
     'vendor1-price': 'US$224',
     'vendor3-price': 'US$242',
     'vendor2-price': 'US$217',
     'vendor3': 'travelup.com', 
     'vendor1': 'Orbitz.com',
     'Hotel': 'Strand Palace Hotel',
     'Best-price': 'US$\xa0223Booking.com',
     'vendor2': 'ZenHotels.com'
    }
  ]
}
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments