Created
December 25, 2025 23:11
-
-
Save hlorand/6f2b1b30f758c29ef2958f1d8da1f5ec to your computer and use it in GitHub Desktop.
Travelodge London Best price finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import urllib.request | |
| import json | |
| from datetime import datetime | |
| # 2025-11-22 2025-11-29 51.512007 -0.108048 | |
| def travelodge(startdate, enddate, lat, lon, maxdistance): | |
| start = datetime.strptime(startdate, "%Y-%m-%d") | |
| end = datetime.strptime(enddate, "%Y-%m-%d") | |
| delta = end - start | |
| # https://d3a3137ptsskfl.cloudfront.net/group_all/ALL/11-22-2025/11-28-2025/51.512007/-0.108048" | |
| url = f"https://d3a3137ptsskfl.cloudfront.net/group_all/ALL/{start.strftime('%m-%d-%Y')}/{end.strftime('%m-%d-%Y')}/{lat}/{lon}/30" | |
| # Load JSON directly from URL | |
| with urllib.request.urlopen(url) as response: | |
| data = json.load(response) | |
| start = f"{startdate}T00:00:00" | |
| end = f"{enddate}T00:00:00" | |
| days = delta.days # last checkout day wont count | |
| rateCode = "SAV" # SAV Non refundable. BAR Fully refundable. Free to amend or cancel up until noon | |
| roomcode = "DBL" # 'roomCode': 'DBL' 'FAM' 'SDBL' 'SFAM | |
| gbp = 448 | |
| hotels = [] | |
| for d in data: | |
| hotels.append({ | |
| 'hotelName' : d['hotelName'], | |
| 'prices' : d['prices'], | |
| 'distance' : round(d['distance']), | |
| 'sumprice' : 0, | |
| 'sumpricelist' : [], | |
| 'daysavailable' : 0 | |
| }) | |
| for h in hotels: | |
| for p in h['prices']: | |
| if start <= p['date'] < end and p['rateCode'] == rateCode and p['roomCode'] == roomcode and p['available'] > 0: | |
| h['sumprice'] += p['price'] | |
| h['sumpricelist'].append( { 'date' : p['date'] , 'price' : p['price'] } ) | |
| h['daysavailable'] += 1 | |
| h['sumprice'] = round(h['sumprice']) | |
| h['sumpricelist'] = sorted(h['sumpricelist'], key=lambda p:p['date']) | |
| #break | |
| hotels = sorted( hotels, key=lambda h:[h['distance'],h['sumprice']] ) | |
| lastd = hotels[0]['distance'] | |
| for h in hotels: | |
| h1 = h['hotelName'].replace('Travelodge London','') | |
| h2 = h['distance'] | |
| h3 = h['sumprice'] | |
| if h['daysavailable'] < days: | |
| continue | |
| if h['distance'] > maxdistance: | |
| continue | |
| #if lastd != h2: | |
| # print("-"*50) | |
| print( f"{startdate}\t{enddate}\t{days}\t{h1}\t{h2}\t{h3}\t{h3*gbp}\t" + "\t".join([ str(p['price']) for p in h['sumpricelist']]) ) | |
| #for p in h['sumpricelist']: | |
| # print(" ", p['date'], p['price']) | |
| lastd = h2 | |
| travelodge("2025-11-26", "2025-12-02", "51.512007", "-0.108048", 3) | |
| #travelodge("2025-11-22", "2025-11-28", "51.512007", "-0.108048", 3) | |
| #travelodge("2025-11-23", "2025-11-29", "51.512007", "-0.108048", 3) | |
| #travelodge("2025-11-24", "2025-11-30", "51.512007", "-0.108048", 3) |
This file has been truncated, but you can view the full file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment