Package: google-flight-analysis
Flight AnalysisThis project provides tools and models for users to analyze, forecast, and collect data regarding flights and prices. There are currently many features in initial stages and in development. The current features (as of 5/25/2023) are:Detailed scraping and querying tools for Google FlightsAbility to store data locally or to SQL tablesBase analytical tools/methods for price forecasting/summaryThe features in development are:Models to demonstrate ML techniques on forecastingQuerying of advanced featuresAPI for access to previously collected dataTable of ContentsOverviewUsageUpdates & New FeaturesReal Usage😄OverviewFlight price calculation can either use newly scraped data (scrapes upon running it) or cached data that reports a price-change confidence determined by a trained model. Currently, many features of this application are in development.UsageThe web scraping tool is currently functional only for scraping round trip flights for a given origin, destination, and date range. It can be easily used in a script or a jupyter notebook.Note that the following packages areabsolutely requiredas dependencies:tqdmselenium(make sure to update yourChromeDriver!)pandasnumpyYou can easily install this by running either installing the Python packagegoogle-flight-analysis:pip install google-flight-analysisor forking/cloning this repository. Upon doing so, make sure to install the dependencies and update ChromeDriver to match your Google Chrome version.pip install -r requirements.txtThe main scraping function that makes up the backbone of most other functionalities isScrape(). It serves also as a data object, preserving the flight information as well as meta-data from your query. For Python package users, import as follows:from google_flight_analysis.scrape import *For GitHub repository cloners, import as follows from the root of the repository:from src.google_flight_analysis.scrape import *
#---OR---#
import sys
sys.path.append('src/google_flight_analysis')
from scrape import *Here is some quick starter code to accomplish the basic tasks. Find more in thedocumentation.# Keep the dates in format YYYY-mm-dd
result = Scrape('JFK', 'IST', '2023-07-20', '2023-08-20') # obtain our scrape object, represents out query
result.type # This is in a round-trip format
result.origin # ['JFK', 'IST']
result.dest # ['IST', 'JFK']
result.dates # ['2023-07-20', '2023-08-20']
print(result) # get unqueried str representationAScrapeobject represents a Google Flights query to be run. It maintains flights as a sequence of one or more one-way flights which have a origin, destination, and flight date. The above object for a round-trip flight from JFK to IST is a sequence of JFK --> IST, then IST --> JFK. We can obtain the data as follows:ScrapeObjects(result) # runs selenium through ChromeDriver, modifies results in-place
result.data # returns pandas DF
print(result) # get queried representation of resultYou can also scrape for one-way trips:results = Scrape('JFK', 'IST', '2023-08-20')
ScrapeObjects(result)
result.data #see dataYou can also scrape chain-trips, which are defined as a sequence of one-way flights that have no direct relation to each other, other than being in chronological order.# chain-trip format: origin, dest, date, origin, dest, date, ...
result = Scrape('JFK', 'IST', '2023-08-20', 'RDU', 'LGA', '2023-12-25', 'EWR', 'SFO', '2024-01-20')
result.type # chain-trip
ScrapeObjects(result)
result.data # see dataYou can also scrape perfect-chains, which are defined as a sequence of one-way flights such that the destination of the previous flight is the origin of the next and the origin of the chain is the final destination of the chain (a cycle).# perfect-chain format: origin, date, origin, date, ..., first_origin
result = Scrape("JFK", "2023-09-20", "IST", "2023-09-25", "CDG", "2023-10-10", "LHR", "2023-11-01", "JFK")
result.type # perfect-chain
ScrapeObjects(result)
result.data # see dataYou can read more about the different type of trips in the documentation. Scrape objects can be added to one another to create larger queries. This is under the conditions:The objects being added are the same type of trip (one-way, round-trip, etc)The objects being added are either both unqueried or both queriedUpdates & New FeaturesPerforming a complete revamp of this package, including new addition to PyPI. Documentation is being updated frequently, contact for any questions.Real UsageHere are some great flights I was able to find and actually booked when planning my travel/vacations:NYC ➡️ AMS (May 9), AMS ➡️ IST (May 12), IST ➡️ NYC (May 23) | Trip Total: $611 as of March 7, 2022