This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jesse Claven
committed
Jan 17, 2022
1 parent
ae4f90b
commit efb3844
Showing
12 changed files
with
341 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Aircraft: | ||
"""Aircraft are used to describe what passengers will fly in for a given trip""" | ||
|
||
def __init__(self, json): | ||
for key in json: | ||
setattr(self, key, json[key]) | ||
id: str | ||
iata_code: str | ||
name: str | ||
|
||
@classmethod | ||
def from_json(cls, json: dict): | ||
"""Construct a class instance from a JSON response.""" | ||
return cls( | ||
id=json["id"], | ||
iata_code=json["iata_code"], | ||
name=json["name"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class Airline: | ||
"""Airlines are used to identify the air travel companies selling and operating | ||
flights | ||
""" | ||
|
||
def __init__(self, json): | ||
for key in json: | ||
setattr(self, key, json[key]) | ||
id: str | ||
name: str | ||
iata_code: str | ||
|
||
@classmethod | ||
def from_json(cls, json: dict): | ||
"""Construct a class instance from a JSON response.""" | ||
return cls( | ||
id=json["id"], | ||
name=json["name"], | ||
iata_code=json["iata_code"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,36 @@ | ||
class Airport: | ||
"""Airports are used to identify origins and destinations in journey slices""" | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
from ..models import City | ||
from ..utils import get_and_transform | ||
|
||
def __init__(self, json): | ||
for key in json: | ||
value = json[key] | ||
if key == "city" and value: | ||
setattr(self, key, City(value)) | ||
else: | ||
setattr(self, key, value) | ||
|
||
@dataclass | ||
class Airport: | ||
"""Airports are used to identify origins and destinations in journey | ||
slices""" | ||
|
||
class City: | ||
"""The metropolitan area where the airport is located. | ||
Only present for airports which are registered with IATA as | ||
belonging to a metropolitan area. | ||
""" | ||
id: str | ||
name: str | ||
iata_code: Optional[str] | ||
icao_code: Optional[str] | ||
country_code: str | ||
latitude: float | ||
longitude: float | ||
time_zone: str | ||
city: Optional[City] | ||
|
||
def __init__(self, json): | ||
for key in json: | ||
setattr(self, key, json[key]) | ||
@classmethod | ||
def from_json(cls, json: dict): | ||
"""Construct a class instance from a JSON response.""" | ||
return cls( | ||
id=json["id"], | ||
name=json["name"], | ||
iata_code=json.get("iata_code"), | ||
icao_code=json.get("icao_code"), | ||
country_code=json["country_code"], | ||
latitude=json["latitude"], | ||
longitude=json["longitude"], | ||
time_zone=json["time_zone"], | ||
city=get_and_transform(json, "city", City.from_json), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class City: | ||
"""The metropolitan area where the airport is located. | ||
Only present for airports which are registered with IATA as | ||
belonging to a metropolitan area. | ||
""" | ||
|
||
id: str | ||
name: str | ||
iata_code: str | ||
iata_country_code: str | ||
|
||
@classmethod | ||
def from_json(cls, json: dict): | ||
"""Construct a class instance from a JSON response.""" | ||
return cls( | ||
id=json["id"], | ||
name=json["name"], | ||
iata_code=json["iata_code"], | ||
iata_country_code=json["iata_country_code"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,19 @@ | ||
|
||
|
||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class LoyaltyProgrammeAccount: | ||
"""A passenger's loyalty programme account""" | ||
|
||
def __init__(self, json): | ||
for key in json: | ||
setattr(self, key, json[key]) | ||
airline_iata_code: str | ||
account_number: str | ||
|
||
@classmethod | ||
def from_json(cls, json: dict): | ||
"""Construct a class instance from a JSON response.""" | ||
return cls( | ||
airline_iata_code=json["airline_iata_code"], | ||
account_number=json["account_number"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,56 @@ | ||
from ..models import City | ||
from dataclasses import dataclass | ||
from typing import Optional, Sequence | ||
|
||
from ..models import Airport, City | ||
from ..utils import get_and_transform | ||
|
||
|
||
@dataclass | ||
class Place: | ||
"""The city or airport""" | ||
|
||
id: str | ||
name: str | ||
type: str | ||
iata_city_code: Optional[str] | ||
iata_country_code: str | ||
latitude: Optional[float] | ||
longitude: Optional[float] | ||
icao_code: Optional[str] | ||
time_zone: Optional[str] | ||
city_name: Optional[str] | ||
city: Optional[City] | ||
airports: Optional[Sequence[Airport]] | ||
|
||
allowed_types = ["airport", "city"] | ||
|
||
class InvalidType(Exception): | ||
"""Invalid type of place""" | ||
|
||
def __init__(self, json): | ||
for key in json: | ||
value = json[key] | ||
if key == "type" and value not in Place.allowed_types: | ||
raise Place.InvalidType(value) | ||
elif key == "city" and value: | ||
value = City(value) | ||
elif key == "airports" and value: | ||
value = [CityAirport(v) for v in value] | ||
setattr(self, key, value) | ||
|
||
|
||
class CityAirport: | ||
"""The airport associated to a city.""" | ||
|
||
def __init__(self, json): | ||
for key in json: | ||
value = json[key] | ||
if key == "city": | ||
value = City(value) | ||
setattr(self, key, value) | ||
def __post_init__(self): | ||
if self.type not in Place.allowed_types: | ||
raise Place.InvalidType(self.type) | ||
|
||
return self | ||
|
||
@classmethod | ||
def from_json(cls, json: dict): | ||
"""Construct a class instance from a JSON response.""" | ||
return cls( | ||
id=json["id"], | ||
name=json["name"], | ||
type=json["type"], | ||
iata_city_code=json.get("iata_city_code"), | ||
iata_country_code=json["iata_country_code"], | ||
latitude=json.get("latitude"), | ||
longitude=json.get("longitude"), | ||
icao_code=json.get("icao_code"), | ||
time_zone=json.get("time_zone"), | ||
city_name=json.get("city_name"), | ||
city=get_and_transform(json, "city", City.from_json), | ||
airports=get_and_transform( | ||
json, | ||
"airports", | ||
lambda value: [Airport.from_json(airport) for airport in value], | ||
), | ||
) |
Oops, something went wrong.