flight_arbitrage.hidden_city module

Find arbitrage in plane ticket prices

class flight_arbitrage.hidden_city.OneWay(leaving_from, going_to, date)

Bases: flight_arbitrage.flight.Flight

Find arbitrage opportunities in one-way flights

cheapest_flight(tries=3)

Finds the cheapest flight that has an arbitrage

Parameters

tries (int) – number of retries to load the site

Return type

Tuple[float, DefaultDict[str, set]]

Returns

the price (if a flight is found) and the flights

static empty_list()
Creates an empty list due to

mypy issue: https://github.com/python/mypy/issues/6463

The type in function ‘retrieve_elements_by_xpath’

variable ‘searching’ defaults to a firefox empty list

Return type

List[FirefoxWebElement]

Returns

a default empty list to help work around a mypy bug

find_arbitrage(override=False, override_filename='airports.txt', web_browser='firefox', driver='', headless=False, tries=3)

Iterates through all possible arbitrage opportunities

Parameters
  • override (bool) – boolean as to whether a custom airport list is needed

  • override_filename (str) – custom airport list text file

  • web_browser (str) – web browser to use

  • driver (str) – web browser selenium driver path

  • headless (bool) – boolean to decide to open a browser in headless mode

  • tries (int) – number of tries to load the website content

Return type

list

Returns

list of arbitrage opportunities and metadata about each

>>> arbitrage = OneWay('JFK', 'SLC', '07/10/2021')
>>> a = arbitrage.find_arbitrage(headless=True)
>>> print(f'Is there an arbitrage opportunity: {len(a) > 0}')
>>> for d in a:
>>>     print(d)
generate_browser()

Opens a browser and goes to the expedia flights website

Return type

None

Returns

nothing

static retrieve_element_by_xpath(base_object, context)

Searches the site for a specific string – context

Parameters
  • base_object – html parent tag object

  • context (str) – string to search

Return type

Union[WebElement, FirefoxWebElement, None]

Returns

xpath object from selenium

retrieve_elements_by_xpath(base_object, context)

Searches the site for a specific string – context

Parameters
  • base_object – html parent tag object

  • context (str) – string to search

Return type

Union[List[WebElement], List[FirefoxWebElement]]

Returns

list of xpath objects from selenium