{"id":1255,"date":"2023-03-04T12:42:10","date_gmt":"2023-03-04T12:42:10","guid":{"rendered":"https:\/\/www.makcorps.com\/blog\/?p=1255"},"modified":"2025-10-17T12:29:22","modified_gmt":"2025-10-17T12:29:22","slug":"develop-hotel-price-monitoring-system","status":"publish","type":"post","link":"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/","title":{"rendered":"How to Develop a Hotel Price Monitoring System Using Python"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.makcorps.com\/blog\/hotel-pricing-monitoring-definition-importance-how-to-do\/\" data-type=\"post\" data-id=\"356\">Hotel price tracking<\/a> has become quite important for the travel industry. There are so many competitors in the market due to keeping track of all the individual OTAs has become quite difficult.<\/p>\n\n\n\n<p>In this article, we are going to use python to create a simple <strong>hotel price-tracking script<\/strong>. We will track hotel prices for a range of dates and whatever date comes out cheaper we are going send ourselves an email with the best offer.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_76 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #e29a12;color:#e29a12\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #e29a12;color:#e29a12\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/#What_do_we_need_before_writing_the_code\" >What do we need before writing the code?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/#What_data_are_we_going_to_search_in_hotel_API\" >What data are we going to search in hotel API?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/#Lets_Start_Tracking_Hotel_Prices\" >Let&#8217;s Start Tracking Hotel Prices<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/#How_to_Mail\" >How to Mail?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/#Complete_Code\" >Complete Code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.makcorps.com\/blog\/develop-hotel-price-monitoring-system\/#Additional_Resources\" >Additional Resources<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_do_we_need_before_writing_the_code\"><\/span>What do we need before writing the code?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We will use&nbsp;<code>Python 3.x<\/code>&nbsp;for this tutorial and I am assuming that you have already installed Python on your machine. The next step would be to create a dedicated folder for our project.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir hotelpricetracker<\/pre>\n\n\n\n<p id=\"6b75\">Then you can create a python file inside this folder. I am naming the file as&nbsp;<code>hotel.py<\/code>.<\/p>\n\n\n\n<p id=\"0af1\">We will also install a library that can make an HTTP connection to the host website. We are going to use&nbsp;<code><a href=\"https:\/\/pypi.org\/project\/requests\/\" target=\"_blank\" rel=\"noreferrer noopener\">requests<\/a><\/code>&nbsp;for that purpose. Here is how you can install it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip install requests<\/pre>\n\n\n\n<p>We also need a&nbsp;<strong><em><a href=\"https:\/\/www.makcorps.com\/blog\/price-apis-for-the-hospitality-industry\/\">hotel API&nbsp;that can pull fresh hotel prices<\/a><\/em><\/strong> from multiple OTAs in just one GET request. For that, we are going to use&nbsp;<a href=\"https:\/\/www.makcorps.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Makcorps Hotel API<\/a>. You can&nbsp;<a href=\"https:\/\/share.hsforms.com\/1A-iwjye2SwWRv4VHhQbBqg439wf\" target=\"_blank\" rel=\"noreferrer noopener\">contact us<\/a>&nbsp;for access to the premium APIs.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"700\" height=\"503\" src=\"https:\/\/www.makcorps.com\/blog\/wp-content\/uploads\/2023\/03\/image.png\" alt=\"\" class=\"wp-image-1258\" srcset=\"https:\/\/www.makcorps.com\/blog\/wp-content\/uploads\/2023\/03\/image.png 700w, https:\/\/www.makcorps.com\/blog\/wp-content\/uploads\/2023\/03\/image-300x216.png 300w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><figcaption class=\"wp-element-caption\">Makcorps Home Page<\/figcaption><\/figure>\n\n\n\n<p>Otherwise, you can just&nbsp;<a href=\"https:\/\/www.makcorps.com\/signup.html\" target=\"_blank\" rel=\"noreferrer noopener\">register<\/a>&nbsp;for the trial pack.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_data_are_we_going_to_search_in_hotel_API\"><\/span>What data are we going to search in hotel API?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"1a13\">Let\u2019s say you want to visit Boston for two days but you want to find out what are the cheapest days. And you want to stay at&nbsp;<a href=\"https:\/\/www.lenoxhotel.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">The Lenox hotel<\/a>. You have holidays from the 11th of March to the 16th of March and you want to find out which check-in date will be the cheapest.<\/p>\n\n\n\n<p id=\"8953\">So, you can check in on the 11th or 12th or 13th or 14th, or 15th of March and you want to book this hotel from either Expedia or Boooking.com.<\/p>\n\n\n\n<p id=\"b772\">So, we are going to get hotel prices from the API for these two OTAs and then compare them for all the dates.<\/p>\n\n\n\n<p id=\"b5ce\">After comparing the prices for all the dates we are going to send an email to ourselves with the cheapest date.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Lets_Start_Tracking_Hotel_Prices\"><\/span>Let&#8217;s Start Tracking Hotel Prices<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"cbe7\">The first step is to import all the libraries that we just installed.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import requests<\/pre>\n\n\n\n<p>Now, we will make a GET request to the hotel API for all the dates one by one using a&nbsp;<code>for loop<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">o={}\nl=[]\nExpediaPrice=[]\nExpediaDate=[]\nBookingPrice=[]\nBookingDate=[]\nfor x in range(0,5):\n    date='2023-03-{}\/2023-03-{}'.format(x+11,x+12)\n    target='https:\/\/api.makcorps.com\/hotelprice\/The%20lenox\/114134\/1\/1\/2023-03-{}\/2023-03-{}?api_key=Your-API-Key'.format(x+11,x+12)\n    resp=requests.get(target).json()\n    for i in range(0,len(resp['comparison'][0])):\n        if(resp['comparison'][0][i]['vendor{}'.format(i+1)] == 'Booking.com'):\n            o[\"BookingPrice\"]=resp['comparison'][0][i][\"price{}\".format(i+1)]\n            o[\"dateB\"]=date\n            l.append(o)\n            o={}\n            continue\n        if(resp['comparison'][0][i]['vendor{}'.format(i+1)] == 'Expedia.com'):\n            o[\"ExpediaPrice\"]=resp['comparison'][0][i][\"price{}\".format(i+1)]\n            o[\"dateE\"]=date\n            l.append(o)\n            o={}\n            continue<\/pre>\n\n\n\n<p id=\"8288\">Let me explain step-by-step what we have done over here.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We have declared some empty arrays and objects.<\/li>\n\n\n\n<li>Then we are running a&nbsp;<code>for loop<\/code>&nbsp;five times because we have five days of holidays and we want to check prices for days falling between those dates.<\/li>\n\n\n\n<li>Using&nbsp;<code>requests<\/code>&nbsp;we have made a&nbsp;<code>GET<\/code>&nbsp;request to the&nbsp;<code>API<\/code>.<\/li>\n\n\n\n<li>Then we again ran a&nbsp;<code>for loop<\/code>&nbsp;to extract prices from each response. Here we are extracting prices of&nbsp;<strong>booking.com<\/strong>&nbsp;and&nbsp;<strong>expedia.com<\/strong>&nbsp;and then storing them in an&nbsp;<code>object o<\/code>.<\/li>\n\n\n\n<li>At the end of the first&nbsp;<code>for<\/code>&nbsp;loop,&nbsp;<code>list l<\/code>&nbsp;will have all the prices and respective dates.<\/li>\n<\/ul>\n\n\n\n<p id=\"e0f6\">If you are wondering what the API response looks like then check this.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n  \"comparison\": [\n    [\n      {\n        \"vendor1\": \"Expedia.com\",\n        \"price1\": \"$169\",\n        \"tax1\": \"$30\"\n      },\n      {\n        \"vendor2\": \"Hotels.com\",\n        \"price2\": \"$169\",\n        \"tax2\": \"$30\"\n      },\n      {\n        \"vendor3\": \"Booking.com\",\n        \"price3\": \"$152\",\n        \"tax3\": \"$27\"\n      },\n      {\n        \"vendor4\": \"eDreams\",\n        \"price4\": \"$152\",\n        \"tax4\": \"$27\"\n      },\n      {\n        \"vendor5\": \"Orbitz.com\",\n        \"price5\": \"$169\",\n        \"tax5\": \"$30\"\n      },\n      {\n        \"vendor6\": \"Travelocity\",\n        \"price6\": \"$169\",\n        \"tax6\": \"$30\"\n      },\n      {\n        \"vendor7\": \"Prestigia.com\",\n        \"price7\": \"$161\",\n        \"tax7\": \"$39\"\n      },\n      {\n        \"vendor8\": \"Hurb\",\n        \"price8\": \"$169\",\n        \"tax8\": \"$35\"\n      },\n      {\n        \"vendor9\": \"Algotels\",\n        \"price9\": null,\n        \"tax9\": null\n      },\n      {\n        \"vendor10\": \"StayForLong\",\n        \"price10\": null,\n        \"tax10\": null\n      },\n      {\n        \"vendor11\": \"Vio.com\",\n        \"price11\": null,\n        \"tax11\": null\n      },\n      {\n        \"vendor12\": \"Official Site\",\n        \"price12\": null,\n        \"tax12\": null\n      },\n      {\n        \"vendor13\": \"Priceline\",\n        \"price13\": null,\n        \"tax13\": null\n      },\n      {\n        \"vendor14\": \"ZenHotels.com\",\n        \"price14\": null,\n        \"tax14\": null\n      },\n      {\n        \"vendor15\": \"Agoda.com\",\n        \"price15\": null,\n        \"tax15\": null\n      },\n      {\n        \"vendor16\": \"Trip.com\",\n        \"price16\": null,\n        \"tax16\": null\n      }\n    ],\n    [\n      \n    ]\n  ]\n}<\/pre>\n\n\n\n<p>Now we have to create separate&nbsp;<code>lists<\/code>&nbsp;for both OTAs. The reason behind this is to sort prices in increasing order at a later stage.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">for p in range(0,len(l)):\n    try:\n        ExpediaPrice.append(int(l[p]['ExpediaPrice'].replace('$','')))\n        ExpediaDate.append(l[p]['dateE'])\n    except:\n        BookingPrice.append(int(l[p]['BookingPrice'].replace('$','')))\n        BookingDate.append(l[p]['dateB'])<\/pre>\n\n\n\n<p id=\"b413\">Here we have created four separate arrays&nbsp;<code>ExpediaPrice<\/code>,&nbsp;<code>ExpediaDate<\/code>,&nbsp;<code>BookingPrice<\/code>&nbsp;and&nbsp;<code>BookingDate<\/code>.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>ExpediaPrice<\/code>&nbsp;will have integer values of price from Expedia.<\/li>\n\n\n\n<li><code>ExpediaDate<\/code>&nbsp;will have dates of that respective price from Expedia.com.<\/li>\n\n\n\n<li><code>BookingPrice<\/code>&nbsp;will have integer values of price from Booking.com.<\/li>\n\n\n\n<li><code>BookingDate<\/code>&nbsp;will have dates of that respective price from Booking.com.<\/li>\n<\/ol>\n\n\n\n<p id=\"7af7\">We have now the data but all we have to do is to sort the prices in increasing order so that we can determine which price is the cheapest and for which date this price is available.<\/p>\n\n\n\n<p id=\"75e7\">We can sort&nbsp;<code>ExpediaPrice<\/code>&nbsp;and&nbsp;<code>BookingPrice<\/code>&nbsp;arrays using&nbsp;<code>.sort()<\/code>&nbsp;method.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ExpediaPrice.sort()\nBookingPrice.sort()<\/pre>\n\n\n\n<p id=\"d7e2\">We have the sorted price but we do not know the dates of these new arrays because the index position of each price has changed now. So, what we can do is record the index position of each price from the original array(without sorting). Through this, we will be able to track down their dates from&nbsp;<code>ExpediaDate<\/code>&nbsp;and&nbsp;<code>BookingDate<\/code>&nbsp;arrays.<\/p>\n\n\n\n<p id=\"84d6\">For this task, we are going to use&nbsp;<code><a href=\"https:\/\/numpy.org\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong><em>Numpy<\/em><\/strong><\/a><\/code><strong><em>.&nbsp;<\/em><\/strong>It is already installed all you have to do is import this into the file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">ExpediaIndex = numpy.array(ExpediaPrice)\nBookingIndex = numpy.array(BookingPrice)\nsort_index_expedia = numpy.argsort(ExpediaIndex)\nsort_index_booking = numpy.argsort(BookingIndex)\nExpediaPrice.sort()\nBookingPrice.sort()<\/pre>\n\n\n\n<p id=\"7f83\">Using&nbsp;<code>.array()<\/code>&nbsp;function we are inserting the target array list which needs to be sorted then using&nbsp;<code>.argsort()<\/code>&nbsp;numpy will provide you a list of indices in increasing order. This is also known as indirect sorting.<\/p>\n\n\n\n<p id=\"3d50\"><code>sort_index_expedia<\/code>&nbsp;and&nbsp;<code>sort_index_booking<\/code>&nbsp;will have the original position of each price. Through this, we can now determine the date of the sorted price list array as well.<\/p>\n\n\n\n<p id=\"0545\">Once you print you will see the cheapest price and date from each OTA.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">print(\"Cheapest Price from Expedia is\", ExpediaPrice[0])\nprint(\"Cheapest Date on Expedia is\", ExpediaDate[sort_index_expedia[0]])\nprint(\"Cheapest Price from Booking.com is\", BookingPrice[0])\nprint(\"Cheapest Date onBooking.com is\", BookingDate[sort_index_booking[0]])<\/pre>\n\n\n\n<p>The only thing which is left is to mail yourself the best offer for your holidays.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Mail\"><\/span>How to Mail?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For mailing, we are going to use&nbsp;<code><a href=\"https:\/\/docs.python.org\/3\/library\/smtplib.html\" target=\"_blank\" rel=\"noreferrer noopener\">smtplib<\/a><\/code>&nbsp;library to send emails using our Gmail account. Again you don\u2019t have to install it, it already comes with Python installation.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def mail(bookingPrice, bookingDate, expediaPrice, expediaDate):\n attackMsg = '''\\\nCheapest Price from Booking.com is {bookingPrice} \\nCheapest Date for Booking.com is {bookingDate} \\nCheapest Price from Expedia.com is {expediaPrice} \\nCheapest Date for Expedia.com is {expediaDate}\n'''.format(bookingPrice=bookingPrice, bookingDate=bookingDate, expediaPrice=expediaPrice, expediaDate=expediaDate)\n server = smtplib.SMTP('smtp.gmail.com', 587)\n server.ehlo()\n server.starttls()\n server.login(\"from@gmail.com\", \"your_passowrd\")\n SUBJECT = \"Price Alert\"\n message = 'From: from@gmail.com \\nSubject: {}\\n\\n{}'.format(SUBJECT, attackMsg)\n server.sendmail(\"from@gmail.com\", 'send_to@gmail.com', message)\n server.quit()\n return True<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The first line defines a function named&nbsp;<code>mail<\/code>&nbsp;that takes four arguments:&nbsp;<code>bookingPrice<\/code>,&nbsp;<code>bookingDate<\/code>,&nbsp;<code>expediaPrice<\/code>, and&nbsp;<code>expediaDate<\/code>.<\/li>\n\n\n\n<li>The second step creates a string variable named&nbsp;<code>attackMsg<\/code>&nbsp;using triple quotes. The string contains placeholders (<code>{}<\/code>) for the four arguments of the function. The&nbsp;<code>format<\/code>&nbsp;method is used to substitute the placeholders with the actual values of the arguments.<\/li>\n\n\n\n<li>The next four lines set up a connection to a Gmail SMTP server using the&nbsp;<code>smtplib<\/code>&nbsp;library. The&nbsp;<code>ehlo<\/code>&nbsp;and&nbsp;<code>starttls<\/code>&nbsp;methods are used to initiate a secure connection. The&nbsp;<code>login<\/code>&nbsp;method is used to authenticate the user with the SMTP server using their email address and password.<\/li>\n\n\n\n<li>Two lines after this define the subject and body of the email message. The&nbsp;<code>message<\/code>&nbsp;variable contains a formatted string that includes the&nbsp;<code>SUBJECT<\/code>&nbsp;variable and the&nbsp;<code>attackMsg<\/code>&nbsp;variable.<\/li>\n\n\n\n<li>The next line sends the email message using the&nbsp;<code>sendmail<\/code>&nbsp;method of the&nbsp;<code>SMTP<\/code>&nbsp;object. The email is sent from the email address specified in the first argument (<code>from@gmail.com<\/code>) to the email address specified in the second argument (<code>send_to@gmail.com<\/code>).<\/li>\n\n\n\n<li>The last two lines close the connection to the SMTP server using the&nbsp;<code>quit<\/code>&nbsp;method and return&nbsp;<code>True<\/code>&nbsp;to indicate that the email was successfully sent.<\/li>\n<\/ul>\n\n\n\n<p id=\"c97d\">You will receive an email that will look like this.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"432\" height=\"112\" src=\"https:\/\/www.makcorps.com\/blog\/wp-content\/uploads\/2023\/03\/image-1.png\" alt=\"\" class=\"wp-image-1259\" style=\"width:432px;height:112px\" srcset=\"https:\/\/www.makcorps.com\/blog\/wp-content\/uploads\/2023\/03\/image-1.png 432w, https:\/\/www.makcorps.com\/blog\/wp-content\/uploads\/2023\/03\/image-1-300x78.png 300w\" sizes=\"auto, (max-width: 432px) 100vw, 432px\" \/><figcaption class=\"wp-element-caption\">Email That You Will Receive<\/figcaption><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Complete_Code\"><\/span>Complete Code<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Now, of course, you can use this code to track prices for a longer range of dates. Using this data you can keep a track of prices offered by your competitors also.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import requests\nimport smtplib, ssl\nimport numpy\ndef mail(bookingPrice, bookingDate, expediaPrice, expediaDate):\n attackMsg = '''\\\nCheapest Price from Booking.com is {bookingPrice} \\nCheapest Date for Booking.com is {bookingDate} \\nCheapest Price from Expedia.com is {expediaPrice} \\nCheapest Date for Expedia.com is {expediaDate}\n'''.format(bookingPrice=bookingPrice, bookingDate=bookingDate, expediaPrice=expediaPrice, expediaDate=expediaDate)\n server = smtplib.SMTP('smtp.gmail.com', 587)\n server.ehlo()\n server.starttls()\n server.login(\"from@gmail.com\", \"your_passowrd\")\n SUBJECT = \"Price Alert\"\n message = 'From: from@gmail.com \\nSubject: {}\\n\\n{}'.format(SUBJECT, attackMsg)\n server.sendmail(\"from@gmail.com\", 'send_to@gmail.com', message)\n server.quit()\n return True\n# l=[{'ExpediaPrice': 565, 'dateE': '2023-03-11\/2023-03-12'}, {'BookingPrice': 565, 'dateB': '2023-03-11\/2023-03-12'}, {'ExpediaPrice': 295, 'dateE': '2023-03-12\/2023-03-13'}, {'BookingPrice': 295, 'dateB': '2023-03-12\/2023-03-13'}, {'ExpediaPrice': 445, 'dateE': '2023-03-13\/2023-03-14'}, {'BookingPrice': 445, 'dateB': '2023-03-13\/2023-03-14'}, {'ExpediaPrice': 455, 'dateE': '2023-03-14\/2023-03-15'}, {'BookingPrice': 455, 'dateB': '2023-03-14\/2023-03-15'}, {'ExpediaPrice': 385, 'dateE': '2023-03-15\/2023-03-16'}, {'BookingPrice': 385, 'dateB': '2023-03-15\/2023-03-16'}]\no={}\nl=[]\nExpediaPrice=[]\nExpediaDate=[]\nBookingPrice=[]\nBookingDate=[]\nfor x in range(0,5):\n    date='2023-03-{}\/2023-03-{}'.format(x+11,x+12)\n    target='https:\/\/api.makcorps.com\/hotelprice\/The%20lenox\/114134\/1\/1\/2023-03-{}\/2023-03-{}?api_key=Your-API-Key'.format(x+11,x+12)\n    print(target)\n    resp=requests.get(target).json()\n    for i in range(0,len(resp['comparison'][0])):\n        if(resp['comparison'][0][i]['vendor{}'.format(i+1)] == 'Booking.com'):\n            o[\"BookingPrice\"]=resp['comparison'][0][i][\"price{}\".format(i+1)]\n            o[\"dateB\"]=date\n            l.append(o)\n            o={}\n            continue\n        if(resp['comparison'][0][i]['vendor{}'.format(i+1)] == 'Expedia.com'):\n            o[\"ExpediaPrice\"]=resp['comparison'][0][i][\"price{}\".format(i+1)]\n            o[\"dateE\"]=date\n            l.append(o)\n            o={}\n            continue\n        # if(len(o) != 0):\nfor p in range(0,len(l)):\n    try:\n        ExpediaPrice.append(int(l[p]['ExpediaPrice'].replace('$','')))\n        ExpediaDate.append(l[p]['dateE'])\n    except:\n        BookingPrice.append(int(l[p]['BookingPrice'].replace('$','')))\n        BookingDate.append(l[p]['dateB'])\nExpediaIndex = numpy.array(ExpediaPrice)\nBookingIndex = numpy.array(BookingPrice)\nsort_index_expedia = numpy.argsort(ExpediaIndex)\nsort_index_booking = numpy.argsort(BookingIndex)\nExpediaPrice.sort()\nBookingPrice.sort()\nmail(BookingPrice[0],BookingDate[sort_index_booking[0]], ExpediaPrice[0], ExpediaDate[sort_index_expedia[0]])\nprint(\"Cheapest Price from Expedia is\", ExpediaPrice[0])\nprint(\"Cheapest Date from Expedia is\", ExpediaDate[sort_index_expedia[0]])\nprint(\"Cheapest Price from Booking.com is\", BookingPrice[0])\nprint(\"Cheapest Date from Booking.com is\", BookingDate[sort_index_booking[0]])<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"125c\">In this tutorial, you learned how to track multiple OTAs with just a simple hotel API. You can use this data for tracking the prices from multiple OTAs or you can show a snippet on your website just beside your own price. You can show that you offer a much lower price than your competitors.<\/p>\n\n\n\n<p id=\"8376\">Of course, there are many applications for this data. If you want to track a large number of hotels then I would advise you to use this API.<\/p>\n\n\n\n<p id=\"407f\">I hope you like this little tutorial and if you do then please do not forget to share it with your friends and on your social media.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Additional_Resources\"><\/span>Additional Resources<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"1f0b\">Here are a few additional resources that you may find helpful during your <a href=\"https:\/\/blog.apify.com\/how-to-scrape-website\/\" target=\"_blank\" rel=\"noopener\">web scraping<\/a> journey:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.makcorps.com\/blog\/yield-management-for-hotels-benefits-and-strategies\/\" target=\"_blank\" rel=\"noreferrer noopener\">Yield Management in the hotel industry<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.makcorps.com\/blog\/hotel-rate-shopper-tools\/\" data-type=\"post\" data-id=\"108\">Best Hotel rate shopping tools<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.makcorps.com\/blog\/hotel-price-forecast\/\" rel=\"noreferrer noopener\" target=\"_blank\">Hotel Price Forecast<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.makcorps.com\/blog\/hotel-data-intelligence\/\" rel=\"noreferrer noopener\" target=\"_blank\">Hotel Data Intelligence<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.makcorps.com\/blog\/ota-insight-alternatives\/\" data-type=\"post\" data-id=\"2920\">Best OTA Insight Alternatives<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Hotel price tracking has become quite important for the travel industry. There are so many competitors in the market due to keeping track of all the individual OTAs has become quite difficult. In this article, we are going to use python to create a simple hotel price-tracking script. We will track hotel prices for a&#8230;<\/p>\n","protected":false},"author":3,"featured_media":1260,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[15],"tags":[],"class_list":["post-1255","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/posts\/1255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/comments?post=1255"}],"version-history":[{"count":8,"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/posts\/1255\/revisions"}],"predecessor-version":[{"id":3246,"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/posts\/1255\/revisions\/3246"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/media\/1260"}],"wp:attachment":[{"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/media?parent=1255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/categories?post=1255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.makcorps.com\/blog\/wp-json\/wp\/v2\/tags?post=1255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}