Find Hotel Price Using the Hotel Price Comparison API using Python11 Jan 2025 | 4 min read In this tutorial, we will write the program to find the hotel price using the hotel price comparison API using Python programming language. We will use the Makcorpse hotel API. This API is used to get the JSON data, and helpful to compare Hotel prices, ratings, and reviews from more than 1500 websites like oyo.com, Hotels.com, Agoda.com, Expedia and more. It is beneficial to retrieve the information of the any hotel or any city regarding prices, ratings, reviews, historical prices and many other things. We need to get the API key to use it our local machine, which we can get from https://www.makcorps.com/ Note - User must be created on makcorps.com then, only register user can use the APIs.We have registered and we will use the sign in credentials to connect with the APIs. Module RequireWe need the requests module to work with the makcorps API. If you don't have requests module, type the following command in the terminal. pip install requests Getting Started with MakCorps APIThis API is designed to provide the data such as reviews, prices, ratings, etc from than 200 vendors such as Booking.com, Agoda.com, Expedia, and Hotels.com. We need to remember the following steps before implementation -
How to get JWT Token?To get the JWT token, the API expose /auth endpoint. We need to pass the username and password in the body. ImplementationWe need to provide the city name to the API to search the hotel prices. Suppose, we search city Delhi, the output JSON will be a price comparison of different hotels in that city from different vendors along with their name. Following is the implementation of the code. Example - 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' } ] } Explanation - In the above code, we have imported the requests module and assigned the request URL to the req_url variable. We also assigned city name that to search in city variable. Then we complete the URL address and store in the complete_url variable. We call the get method on the given URL and pass the header. The header must include the JWT token that we get from /auth API. The API return the response that we convert JSON format data into Python format code. Now we check the value of the status code is equal to 200 or not, if equal that means record is found otherwise record is not found. Hence we returned the fetched result. ConclusionIn this tutorial, we have learned the how to fetch the prices of the hotels and compare. The Makcorps API will help to choose the lowest price hotels in the searched city. Next TopicGet Started with RabbitMQ and Python |
Every time a user submits an input, it must be validated to see if it is exactly what we expected. We can validate the input in one of two ways: by applying a flag variable or implementing try or except. The flag variable will be originally...
6 min read
In this tutorial, we will learn how to flush the output data buffer explicitly using the flush parameter of the print() function. We will also determine when we need to flush the data buffer and when we don't need it. We will also discuss changing data...
10 min read
Clone the Linked List with Random and Pointer in Python A linked list is created using a random pointer. Given an N-by-N linked list, where each node has two connections, one pointing to the node after it and the other to any node in the list....
7 min read
In Python, we have many in-built modules for performing various tasks, and one of such tasks we want to perform with the Python modules is finding and locating all the files present in our system, which follows a similar pattern. This similar pattern can be a...
10 min read
Red-Black Trees A red-black tree is a binary search tree with the additional property of being "nearly" adjusted. Every node in a red-black tree has a color, either red or black, and these colors are utilized to keep up with balance during insertions and deletions. Deletion: BST Deletion: Begin by...
10 min read
Amazon PI (Performance Intelligence) is a tool developed by Amazon Web Services (AWS) to help customers monitor and optimize the performance of their applications on the AWS platform. With Amazon PI, users can easily identify performance bottlenecks, troubleshoot issues, and make informed decisions to improve the...
6 min read
In the following tutorial, we will learn about the Bisect algorithms with the help of the bisect module in the Python programming language. Understanding the Python bisect module The purpose of the Bisect algorithm is to find a position in the list where a data element must be...
6 min read
In this tutorial, we will learn about the Python libraries for the PDF data extract for further analysis. We will go through the essential Python libraries. PDF is a portable document format which is generally used to store data safely. PDF resumes are created in various ways....
6 min read
In this tutorial, we will learn how to create different types of hollow pyramid patterns using Python. Program 1: Program to make a simple hollow pyramid in Python Code: def hollow_pyramid( r ) : m = 0 for n in range(1, r +...
6 min read
What is a Recipe Recommender System? In today's fast-paced world, most people are looking for quick and easy solutions to their daily problems. One of these problems is deciding what to cook for their meals. While many people enjoy cooking, others may find it challenging to come...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India