flightbyte 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flightbyte/__init__.py +136 -0
- flightbyte/_client.py +157 -0
- flightbyte/_countries.py +57 -0
- flightbyte/_errors.py +311 -0
- flightbyte/_flights.py +84 -0
- flightbyte/_models.py +644 -0
- flightbyte/_rate_limit.py +75 -0
- flightbyte/_subscriptions.py +317 -0
- flightbyte/_transport.py +429 -0
- flightbyte/_util.py +28 -0
- flightbyte/_version.py +3 -0
- flightbyte/_webhook.py +233 -0
- flightbyte/py.typed +0 -0
- flightbyte-1.0.0.dist-info/METADATA +423 -0
- flightbyte-1.0.0.dist-info/RECORD +17 -0
- flightbyte-1.0.0.dist-info/WHEEL +4 -0
- flightbyte-1.0.0.dist-info/licenses/LICENSE +21 -0
flightbyte/_flights.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Flight lookups."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import cast
|
|
6
|
+
|
|
7
|
+
from ._models import FlightSnapshot, FlightTimeline
|
|
8
|
+
from ._transport import NOT_GIVEN, NotGiven, Transport, required
|
|
9
|
+
|
|
10
|
+
__all__ = ["Flights"]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Flights:
|
|
14
|
+
"""Flight lookups. Reach it as ``client.flights``."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, transport: Transport) -> None:
|
|
17
|
+
self._transport = transport
|
|
18
|
+
|
|
19
|
+
def get(
|
|
20
|
+
self,
|
|
21
|
+
carrier: str,
|
|
22
|
+
flight_number: str,
|
|
23
|
+
date: str,
|
|
24
|
+
*,
|
|
25
|
+
origin: str | None = None,
|
|
26
|
+
destination: str | None = None,
|
|
27
|
+
flight_id: str | None = None,
|
|
28
|
+
refresh: bool = False,
|
|
29
|
+
timeout: float | NotGiven | None = NOT_GIVEN,
|
|
30
|
+
) -> FlightSnapshot:
|
|
31
|
+
"""Looks a flight up.
|
|
32
|
+
|
|
33
|
+
The API upper-cases the carrier and strips leading zeros from the
|
|
34
|
+
flight number. ``date`` is the local departure date at the origin,
|
|
35
|
+
``YYYY-MM-DD``; ``FlightByte.format_date`` makes one.
|
|
36
|
+
|
|
37
|
+
A flight number can fly several legs on one date. The snapshot lists
|
|
38
|
+
them all in ``alternates``; pass ``origin`` (and optionally
|
|
39
|
+
``destination``) or a leg's ``flight_id`` to choose one. ``refresh``
|
|
40
|
+
skips the API's cache and asks upstream.
|
|
41
|
+
|
|
42
|
+
Raises:
|
|
43
|
+
NotFoundError: The flight did not operate that day.
|
|
44
|
+
"""
|
|
45
|
+
result = self._transport.send(
|
|
46
|
+
"GET",
|
|
47
|
+
_flight_path(carrier, flight_number, date),
|
|
48
|
+
query={
|
|
49
|
+
"origin": origin,
|
|
50
|
+
"destination": destination,
|
|
51
|
+
"flightId": flight_id,
|
|
52
|
+
"refresh": "true" if refresh else None,
|
|
53
|
+
},
|
|
54
|
+
timeout=timeout,
|
|
55
|
+
)
|
|
56
|
+
return cast(FlightSnapshot, result)
|
|
57
|
+
|
|
58
|
+
def timeline(
|
|
59
|
+
self,
|
|
60
|
+
carrier: str,
|
|
61
|
+
flight_number: str,
|
|
62
|
+
date: str,
|
|
63
|
+
*,
|
|
64
|
+
origin: str | None = None,
|
|
65
|
+
destination: str | None = None,
|
|
66
|
+
timeout: float | NotGiven | None = NOT_GIVEN,
|
|
67
|
+
) -> FlightTimeline:
|
|
68
|
+
"""The flight's change history as recorded by the API, newest first."""
|
|
69
|
+
result = self._transport.send(
|
|
70
|
+
"GET",
|
|
71
|
+
[*_flight_path(carrier, flight_number, date), "timeline"],
|
|
72
|
+
query={"origin": origin, "destination": destination},
|
|
73
|
+
timeout=timeout,
|
|
74
|
+
)
|
|
75
|
+
return cast(FlightTimeline, result)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _flight_path(carrier: str, flight_number: str, date: str) -> list[str]:
|
|
79
|
+
return [
|
|
80
|
+
"flights",
|
|
81
|
+
required("carrier", carrier),
|
|
82
|
+
required("flight_number", flight_number),
|
|
83
|
+
required("date", date),
|
|
84
|
+
]
|