Code Monkey home page Code Monkey logo

flight-search's Introduction

Flight search / Qatar Airways site crawler

A simple tool to monitor business class fares for Qatar Airways. It fills search forms and then clicks (1) one week forward for outbound flight and (2) one week forward for inbound flight and stores output pages as html files in html/ directory. Then you can use a sample parser I wrote to get the cheapest price and dates.

The script may return errors when site session expires or if it can't get another site etc. After error a screenshot is taken and stored in file qatar-error.png.

To see browser window while running, use -v option.

Intallation

  1. Download geckodriver binary from https://github.com/mozilla/geckodriver/releases/tag/v0.24.0, uncompress it and save in the project directory.

  2. Create virtualenv with python3 -m venv venv. Activate it source venv/bin/activate

  3. Install pip packages pip install -r requirements.txt

Usage

Options

python search.py --help

usage: search.py [-h] [-f FROM_AIRPORT] [-t TO_AIRPORT] [-a {qatar}] [-d DATE]
                 [-w WEEKS] [-m MONTHS] [-c {business,economy}]

Search flight prices

optional arguments:
  -h, --help            show this help message and exit
  -f FROM_AIRPORT, --from FROM_AIRPORT
                        Flight origin (default: WAW)
  -t TO_AIRPORT, --to TO_AIRPORT
                        Flight destination (default: AKL)
  -a {qatar}, --airlines {qatar}
                        Airlines name (default: qatar)
  -d DATE, --date DATE  Departure date YYYY-MM-DD (default: 2019-05-19)
  -w WEEKS, --weeks WEEKS
                        Return flight after this number of weeks (default: 3)
  -m MONTHS, --search-months MONTHS
                        Stop search after this number of months (default: 6)
  -c {business,economy}, --class {business,economy}
                        Travel class (default: business)

Flight search example

Search flights by Qatar Airlines (only this one is supported for now) from Warsaw to Aukland, 10 months forward with 3 week difference between departure and arrival date.

python search.py -m 10 -f WAW -t AKL -w 3

To see browser window while running, add -v option. Please take note it will be of size 2560x1440.

Crawled sites are stored in htmls/. Simple parser is also available:

# Remeber to change directory name
python parse.py htmls/qatar/201905191538-WAW:AKL-business/

Sample output

Searcher:

$ python search.py -f WAW -t AKL -m 6 -w 3
=> QATAR SEARCH (until 19 Nov 2019)
   flight:      WAW-AKL Business
   departure:   19 May 2019
   return:      09 Jun 2019
   > waiting for the next  inbound page... got 16 Jun 2019
   > waiting for the next outbound page... got 26 May 2019
   > waiting for the next  inbound page... got 23 Jun 2019
   > waiting for the next outbound page... got 02 Jun 2019
   > waiting for the next  inbound page... got 30 Jun 2019
   > waiting for the next outbound page... got 09 Jun 2019
[...]
   > waiting for the next outbound page... got 17 Nov 2019
   > waiting for the next  inbound page... got 15 Dec 2019
   > waiting for the next outbound page... got 24 Nov 2019

Parser:

$ python parse.py htmls/qatar/201905191651-WAW:AKL-business/
> Parsing file htmls/qatar/201905191651-WAW:AKL-business/qatar-business-WAW:AKL-20190519:20190609-20190519:20190609.html
Minimal outbound price 22 May 2019: 11534.86
Minimal inbound price  06 Jun 2019: 8401.56
Total price: 19936.42

> Parsing file htmls/qatar/201905191651-WAW:AKL-business/qatar-business-WAW:AKL-20190519:20190609-20190519:20190616.html
Minimal outbound price 22 May 2019: 11534.86
Minimal inbound price  13 Jun 2019: 8401.56
Total price: 19936.42

> Parsing file htmls/qatar/201905191651-WAW:AKL-business/qatar-business-WAW:AKL-20190519:20190609-20190526:20190616.html
Minimal outbound price 23 May 2019: 11534.86
Minimal inbound price  13 Jun 2019: 8401.56
Total price: 19936.42
[...]

> Parsing file htmls/qatar/201905191651-WAW:AKL-business/qatar-business-WAW:AKL-20190519:20190609-20191110:20191208.html
Minimal outbound price 08 Nov 2019: 8466.81
Minimal inbound price  05 Dec 2019: 8409.52
Total price: 16876.33

> Parsing file htmls/qatar/201905191651-WAW:AKL-business/qatar-business-WAW:AKL-20190519:20190609-20191117:20191208.html
Minimal outbound price 14 Nov 2019: 8466.81
Minimal inbound price  05 Dec 2019: 8409.52
Total price: 16876.33

> Parsing file htmls/qatar/201905191651-WAW:AKL-business/qatar-business-WAW:AKL-20190519:20190609-20191117:20191215.html
Minimal outbound price 15 Nov 2019: 8466.81
Minimal inbound price  12 Dec 2019: 8409.52
Total price: 16876.33

MINIMAL TOTAL PRICE (17 Aug 2019 - 08 Sep 2019): 16876.33

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.