Giter Site home page Giter Site logo

stnorbi / flight_search Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 47 KB

Project focuses on develop a search script runable on terminal (without GUI) due to requirements (raised in https://github.com/kiwicom/python-weekend-entry-task).

Python 100.00%

flight_search's Introduction

Project Title

Solution of Python Weekend Entry Task (2022)

Status GitHub Issues GitHub Pull Requests License


Purpose of current project is to get attendance to "Kiwi.com Python Weekend" in 2022 march 4-6.

๐Ÿ“ Table of Contents

๐Ÿง About

Project focuses on develop a search script runable on terminal (without GUI) due to requirements (raised in https://github.com/kiwicom/python-weekend-entry-task).

๐Ÿ Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

At least Python 3.8.10 be installed on your computer.

Please visit python.org and download it via the link below.
https://www.python.org/downloads/

Only the standard libraries are necessary to execute the script, no need 3rd party packages, notebooks, specialized distros (Conda) etc. The code should run as is, no environment setup is required.

Installing

Extract the received ZIP file in case of getting it via email or downloading it from git repo in that format. Using (Ubuntu) Linux OS, such as:

unzip flight_search-master.zip

Extract the received ZIP file in case of using Windows OS command line:

tar -xf flight_search-master.zip

You have to get the following directory structure within flight_search-master folder:

โ”œโ”€โ”€ example
โ”‚   โ”œโ”€โ”€ example0.csv
โ”‚   โ”œโ”€โ”€ example1.csv
โ”‚   โ”œโ”€โ”€ example2.csv
โ”‚   โ””โ”€โ”€ example3.csv
โ”œโ”€โ”€ modules
โ”‚   โ”œโ”€โ”€ data_validation.py
โ”‚   โ”œโ”€โ”€ flights.py
โ”‚   โ””โ”€โ”€ __init__.py
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ solution.py

example/*.csv:

  • Input files for testing purpose

solution.py:

  • It gets the parameters (mandatory & optionals - see in further subchapters below) from console and includes the execution function of the search-engine module, so called flights. It calls search function from flights module and validate the parameters got from terminal. If any of the mandatory or optional parameters is wrong the following error message retruns, without keep running:
# ERROR MESSAGE
One of the arguments is invalid!!

modules/flights.py:

  • It contains those functions which are necessary to derive proper search result(s):
  • set_result --> writes the result set into json_data.json and to the terminal with the number of flights found.
  • get_traveltime --> converts string timestamp into ISO format and returns how much time the travel take.
  • get_overlay --> calculates time between flight changes
  • read_csv --> read csv input file and validate input data records according to definitions in modules/data_validation.py
  • get_flights --> based on search parameters, this function is the core-engine of the task. It calls get_traveltime and get_overlay
    functions.
  • search --> calles direct or indirect way every function in this module by splitting the return and non-return searches.

modules/data_validation.py:

  • Functions of current module go through the atributes in input file and flag if any error would be detected:
  • flight_no_checker --> returns error message if fligh number is not equal to 5 (supposing according to - example - input files this is the standard length) or its characters massed up.
# ERROR MESSAGE
  Input file contains invalid flight number such as '[FLIGHT_NO]'!
  • geo_checkor --> validates if airport codes correctness. If airport code is not 3 character long and it is not string following error message returns:
# ERROR MESSAGE
'[GEO_CODE]' is not a valid geo code to '[ARRIVAL / DEPARTURE]' airport. Please fix adequate field of input file!
  • timestamp_checker --> handles error of incorrect format of timestamp regarding arrival / departure time
# ERROR MESSAGE
Sorry but date format of '[ARRIVAL / DEPARTURE TIMESTAMP]' is unacceptable in the field '[ARRIVAL / DEPARTURE TIME COLUMN]' of input file: '[VALUE ERROR MESSAGE]'
  • integer_checker --> returns error message if called column of input file contains data type apart of integer. It validates string representation of integers.
# ERROR MESSAGE
[NUMBER] is not a number in '[COLUMNNAME]' field. Please fix adequate field of input file!
  • float_checker --> regarding float number validation and error handling
# ERROR MESSAGE
'[NUMBER]' is not a number. Please fix adequate field of input file!

๐ŸŽˆ Usage

Step into the folder where solution.py script is:

List of mandatory arguments of the solution python module:

Argument name type Description Notes
filepath string filepath of csv file, which has proper structure with all necessary input data (see an example file attached) Mandatory
origin string Origin (departure) site where You would like to travel from Mandatory
destination string Destination (arrival) site where You would like to travel to Mandatory

1. Execution

If you just want to run a search on airports code without any additional filter, run the following command:

    python -m solution  example/example3.csv BPZ WTN

There are two other optional argument which can be used to tune up Your search:

Argument name type Description Notes
bags integer Number of requested bags Optional (defaults to 0)
return boolean Is it a return flight? Optional (defaults to false)

2. Execution

a) scenario, if you want to search for flights which allow at least one lagguage to take. NOTE: Changing flights take a look at what is the maxium number of bag can be taken because of "bag allowance". It can reduce your results. (e.g. your 1st flight allows 2 bags, but changing to the 2nd one it just allows 1)

  python -m solution  example/example3.csv BPZ WTN --bags=1
  
  #OR
  python -m solution  example/example3.csv BPZ WTN -b 1

b) scenario, if you want to search return flights as well with one lagguage.

  • NOTE: Take into account overlay limitations are also used in case of return flights and the lagguage limitation as well.
  python -m solution  example/example3.csv BPZ WTN --bags=1 --return

  #OR
  python -m solution  example/example3.csv BPZ WTN -b 1 -r

After running the parameterized module, the search result will be printed to console and saved in json_data.json file in the current directory. Providing bags with greater than 0 value, it will be utilized in case of flight changes, so it has to be less than or equal to smaller bag allowance limitation. Providing return argument, the result set will include the "ways there" and "return journeys" as well.

python -m solution example/example0.csv WIW ECV --bags=1 --return

RESULT SET is a json-compatible structured list of trips sorted by total_price (ascending order alias cheapest is first):

[
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "WIW",
                "destination": "ECV",
                "departure": "2021-09-01T07:25:00",
                "arrival": "2021-09-01T12:35:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "ECV",
        "origin": "WIW",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    },
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "WIW",
                "destination": "ECV",
                "departure": "2021-09-02T07:25:00",
                "arrival": "2021-09-02T12:35:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "ECV",
        "origin": "WIW",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    },
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "WIW",
                "destination": "ECV",
                "departure": "2021-09-06T07:25:00",
                "arrival": "2021-09-06T12:35:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "ECV",
        "origin": "WIW",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    },
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "WIW",
                "destination": "ECV",
                "departure": "2021-09-11T07:25:00",
                "arrival": "2021-09-11T12:35:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "ECV",
        "origin": "WIW",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    },
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "ECV",
                "destination": "WIW",
                "departure": "2021-09-01T15:35:00",
                "arrival": "2021-09-01T20:45:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "WIW",
        "origin": "ECV",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    },
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "ECV",
                "destination": "WIW",
                "departure": "2021-09-02T15:35:00",
                "arrival": "2021-09-02T20:45:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "WIW",
        "origin": "ECV",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    },
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "ECV",
                "destination": "WIW",
                "departure": "2021-09-06T15:35:00",
                "arrival": "2021-09-06T20:45:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "WIW",
        "origin": "ECV",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    },
    {
        "flights": [
            {
                "flight_no": "ZH151",
                "origin": "ECV",
                "destination": "WIW",
                "departure": "2021-09-11T15:35:00",
                "arrival": "2021-09-11T20:45:00",
                "base_price": "245.0",
                "bag_price": "12",
                "bags_allowed": "2"
            }
        ],
        "bags_allowed": "2",
        "bags_count": 1,
        "destination": "WIW",
        "origin": "ECV",
        "total_price": 257.0,
        "travel_time": "5:10:00"
    }
]


โ›๏ธ Built Using

  • Ubuntu 20.04 LTS
  • Python 3.8
  • CSV file storage

โœ๏ธ Authors

๐ŸŽ‰ Acknowledgements

flight_search's People

Contributors

stnorbi avatar

Watchers

 avatar

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.