Skip to content

Instantly share code, notes, and snippets.

@ibaaj
Created April 30, 2017 21:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibaaj/24c2fab42e4ab32867556457f89688b9 to your computer and use it in GitHub Desktop.
Save ibaaj/24c2fab42e4ab32867556457f89688b9 to your computer and use it in GitHub Desktop.
track flight price drops
from google_flight import google_flight_api
from pushbullet import Pushbullet
import datetime
import time
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
g = google_flight_api.GoogleFlight("XXXXXXXXXXXX")
pb = Pushbullet("XXXXXXXXXXXXXXXXXXXXXXXXXX")
start_date = datetime.datetime.now()
x = []
y = []
for day in range(0,50):
start_date += datetime.timedelta(days=1)
x.append(start_date)
data = {
"request": {
"slice": [
{
"origin": "ORY",
"destination": "LIM",
"date": start_date.strftime("%Y-%m-%d")
},
],
"passengers": {
"adultCount": 1,
"infantInLapCount": 0,
"infantInSeatCount": 0,
"childCount": 0,
"seniorCount": 0
},
"solutions": 1,
"refundable": 'false'
}
}
g.get(data)
lowest = g.lowest()
price = float(lowest.saleTotal[3:])
y.append(price)
print(price)
time.sleep(1)
minPrice = min(y)
indexPrice = y.index(minPrice)
minDate = x[indexPrice]
push = pb.push_note("ORY->LIM EUR" + str(minPrice) + " le " + minDate.strftime('%d-%m'), "")
fig, ax = plt.subplots()
ax.plot(x,y)
fig.autofmt_xdate()
myFmt = mdates.DateFormatter("%d/%m")
ax.xaxis.set_major_formatter(myFmt)
ax.set_xlabel('Date')
ax.set_ylabel('Prix')
fig.suptitle('Prix billet ORY -> LIM', fontsize=14, fontweight='bold')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment