Calculate flight distance (using Vincenty's formulae) and classify flight in short/middle/long (according to this classification).
- Clone or download repo
- Cd into repo
pip install .
- try it:
flight-distance classify FRA ABC
Usage: flight-distance [OPTIONS] COMMAND [ARGS]...
Options:
--install-completion Install completion for the current shell.
--show-completion Show completion for the current shell, to copy it or
customize the installation.
--help Show this message and exit.
Commands:
classify Classify a single flight
classify-batch Classify a batch of flights
schemas Show json schema(s)
E.g. flight-distance classify FRA ABC
Usage: flight-distance classify [OPTIONS] DEPARTURE_IATA ARRIVAL_IATA [WRITE_TO]
Classify a single flight
Arguments:
DEPARTURE_IATA [required]
ARRIVAL_IATA [required]
[WRITE_TO] Write output to PATH
Options:
--help Show this message and exit.
E.g.: flight-distance classify-batch in.json out.json
Usage: flight-distance classify-batch [OPTIONS] READ_FROM [WRITE_TO]
Classify a batch of flights
Duplicate flights in `read_from` are ignored.
Arguments:
READ_FROM [required]
[WRITE_TO] Write output to PATH
Options:
--help Show this message and exit.
Cf. flight-distance schemas
[
{
"arrival": {
"iata": "STR"
}
},
{
"depature": {
"iata": "CHQ"
}
}
]
{
"title": "ReadFlights",
"type": "array",
"items": {
"$ref": "#/definitions/ReadFlight"
},
"definitions": {
"ReadAirport": {
"title": "ReadAirport",
"type": "object",
"properties": {
"iata": {
"title": "Iata",
"minLength": 3,
"maxLength": 3,
"pattern": "^[a-zA-Z-0-9]+$",
"type": "string"
}
},
"required": ["iata"]
},
"ReadFlight": {
"title": "ReadFlight",
"type": "object",
"properties": {
"departure": {
"$ref": "#/definitions/ReadAirport"
},
"arrival": {
"$ref": "#/definitions/ReadAirport"
}
},
"required": ["departure", "arrival"]
}
}
}
{
"departure": "FRA",
"departure_country": "DE",
"arrival": "ABC",
"arrival_country": "ES",
"distance": 1481,
"type": "short"
}
{
"title": "ClassifiedFlight",
"type": "object",
"properties": {
"departure": {
"title": "Departure",
"minLength": 3,
"maxLength": 3,
"pattern": "^[a-zA-Z-0-9]+$",
"type": "string"
},
"departure_country": {
"title": "Departure Country",
"minLength": 2,
"maxLength": 2,
"pattern": "^[a-zA-Z]+$",
"type": "string"
},
"arrival": {
"title": "Arrival",
"minLength": 3,
"maxLength": 3,
"pattern": "^[a-zA-Z-0-9]+$",
"type": "string"
},
"arrival_country": {
"title": "Arrival Country",
"minLength": 2,
"maxLength": 2,
"pattern": "^[a-zA-Z]+$",
"type": "string"
},
"distance": {
"title": "Distance",
"exclusiveMinimum": 0,
"type": "integer"
},
"type": {
"$ref": "#/definitions/FlightType"
}
},
"required": [
"departure",
"departure_country",
"arrival",
"arrival_country",
"distance"
],
"definitions": {
"FlightType": {
"title": "FlightType",
"description": "An enumeration.",
"enum": ["short", "middle", "long"],
"type": "string"
}
}
}
[
{
"departure": "STR",
"departure_country": "DE",
"arrival": "CHQ",
"arrival_country": "GR",
"distance": 1906,
"type": "middle"
}
]
{
"title": "ClassifiedFlights",
"type": "array",
"items": {
"$ref": "#/definitions/ClassifiedFlight"
},
"definitions": {
"FlightType": {
"title": "FlightType",
"description": "An enumeration.",
"enum": ["short", "middle", "long"],
"type": "string"
},
"ClassifiedFlight": {
"title": "ClassifiedFlight",
"type": "object",
"properties": {
"departure": {
"title": "Departure",
"minLength": 3,
"maxLength": 3,
"pattern": "^[a-zA-Z-0-9]+$",
"type": "string"
},
"departure_country": {
"title": "Departure Country",
"minLength": 2,
"maxLength": 2,
"pattern": "^[a-zA-Z]+$",
"type": "string"
},
"arrival": {
"title": "Arrival",
"minLength": 3,
"maxLength": 3,
"pattern": "^[a-zA-Z-0-9]+$",
"type": "string"
},
"arrival_country": {
"title": "Arrival Country",
"minLength": 2,
"maxLength": 2,
"pattern": "^[a-zA-Z]+$",
"type": "string"
},
"distance": {
"title": "Distance",
"exclusiveMinimum": 0,
"type": "integer"
},
"type": {
"$ref": "#/definitions/FlightType"
}
},
"required": [
"departure",
"departure_country",
"arrival",
"arrival_country",
"distance"
]
}
}
}
The data in airports.json
is public domain. Nearly all airports came from here.
This dataset doesn't cover all airports with IATA codes. According to IATA there are about 11k airports with IATA codes. airports.json has about 9.5k of them.