Last active
September 9, 2023 09:54
-
-
Save Bersam/67489d052cbb839e37624cd7f124ad07 to your computer and use it in GitHub Desktop.
fetch lowest flight price in next two weeks from sepehr360
This file contains 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
#!/usr/bin/python | |
import requests | |
from datetime import datetime, timedelta | |
# Config: | |
source = "THR,IKA" | |
destination = "BND" | |
sthreshold = 130 # hezar toman, color (soft) threshold | |
hthreshold = 170 # toggle (hard) threshold | |
print_friendly = True | |
#start_str = "2018/01/17" | |
#end_str = "2018/01/23" | |
#start = datetime.strptime(start_str, "%Y/%m/%d") | |
#end = datetime.strptime(end_str, "%Y/%m/%d") | |
start = datetime.today() | |
end = start + timedelta(15) | |
# Request: | |
r = requests.post( | |
url='https://sepehr360.com/fa/Api/CalendarApi/SetFlightMonthHistory', | |
data={ | |
"source": source, | |
"destination": destination, | |
"currencyType": "IRR" | |
}) | |
result = r.json() | |
filtered_result = [ | |
i for i in result['Arrival'] | |
if (datetime.strptime(i['FlightDate'][:10], "%Y-%m-%d") >= start | |
and datetime.strptime(i['FlightDate'][:10], "%Y-%m-%d") <= end) | |
] | |
event = min(filtered_result, key=lambda ev: int(ev['Price'])) | |
if print_friendly: | |
if float(event['Price']) <= hthreshold: | |
print( | |
"✈ <font color='{color}'>{source}->{dest}: {date}, {currency}{price:,.0f}</font>". | |
format( | |
source=source[:3], | |
dest=destination[:3], | |
date=event["Date"], | |
price=float(event["Price"]) * 10 * 1000, | |
currency="﷼", | |
color='green' | |
if float(event["Price"]) <= sthreshold else 'darkgrey')) | |
else: | |
print("<font color='black'> <font>") | |
else: | |
print("%s, %s, %s, %s" % (source[:3], destination[:3], event["Date"], event["Price"])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment