Utilities
Mostly used in the service.
utils
¤
Classes:
Name | Description |
---|---|
BarePath |
|
SupportsToDict |
|
SupportsToPolars |
|
Ok |
|
Err |
|
UnwrapError |
|
ParamDetail |
|
SphinxParser |
A poor man's parser for Sphinx docstrings and its |
Functions:
Name | Description |
---|---|
dataclass_frozen |
|
to_unix_timestamp |
Casts timestamp-like object to a Unix timestamp in integer seconds. |
get_current_timestamp |
Returns the current Unix timestamp in seconds. |
parse_server_timestamp |
|
to_flight_id |
|
to_flight_id_hex |
Converts flight ID to a hex string. |
format_bare_path |
|
write_table |
Writes the table as the specified format via polars. |
scan_table |
Reads the table as the specified format via polars. |
static_check_signature |
Marker to signal the static analyser that the decorated method or |
Attributes:
Name | Type | Description |
---|---|---|
dataclass_opts |
dict[str, bool]
|
|
logger |
|
|
DEFAULT_HEADERS |
|
|
FileLike |
|
|
FileExistsBehaviour |
TypeAlias
|
|
DictT_co |
The dictionary representation of an object, e.g. |
|
T |
|
|
E |
|
|
Result |
TypeAlias
|
A type that represents either success ( |
M |
|
DEFAULT_HEADERS
module-attribute
¤
DEFAULT_HEADERS = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, zstd",
"Origin": "https://www.flightradar24.com",
"Connection": "keep-alive",
"Referer": "https://www.flightradar24.com/",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
"TE": "trailers",
}
FileExistsBehaviour
module-attribute
¤
FileExistsBehaviour: TypeAlias = Literal[
"backup", "error", "overwrite"
]
DictT_co
module-attribute
¤
DictT_co = TypeVar('DictT_co', covariant=True)
The dictionary representation of an object, e.g. TypedDict
.
Result
module-attribute
¤
A type that represents either success (Ok
) or failure (Err
).
SupportsToDict
¤
SupportsToPolars
¤
Ok
¤
Err
¤
UnwrapError
¤
ParamDetail
¤
SphinxParser
dataclass
¤
to_unix_timestamp
¤
to_unix_timestamp(
timestamp: IntoTimestamp | Literal["now"] | str,
) -> IntTimestampS | Literal["now"]
to_unix_timestamp(timestamp: None) -> None
to_unix_timestamp(
timestamp: IntoTimestamp | str | Literal["now"] | None,
) -> IntTimestampS | Literal["now"] | None
Casts timestamp-like object to a Unix timestamp in integer seconds.
get_current_timestamp
¤
get_current_timestamp() -> IntTimestampS
Returns the current Unix timestamp in seconds.
to_flight_id_hex
¤
to_flight_id_hex(flight_id: IntoFlightId) -> StrFlightIdHex
Converts flight ID to a hex string.
write_table
¤
write_table(
result: SupportsToPolars,
file: FileLike,
*,
format: TabularFileFmt = "parquet",
when_file_exists: FileExistsBehaviour = "backup",
**kwargs: Any,
) -> None
scan_table
¤
scan_table(
file: FileLike,
*,
format: TabularFileFmt = "parquet",
schema: dict[str, DataType] | None = None,
) -> LazyFrame
Reads the table as the specified format via polars.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
FileLike
|
File path or readable file-like object. The path will be given an appropriate suffix if it is a BarePath. |
required |
schema
|
dict[str, DataType] | None
|
The schema to enforce when reading the table. For CSV files, this should be specified to properly parse datetimes from strings. |
None
|
static_check_signature
¤
Marker to signal the static analyser that the decorated method or function should be checked against the signature of the given dataclass.
Many of our low level APIs use 1) parameters stored in a single flat dataclass, and 2) functions that take in this dataclass:
@dataclass
class LiveFeedParams:
bbox_south: float
"""Latitude, minimum, degrees"""
bbox_north: float
bbox_west: float
bbox_east: float
flight_id: int
# ... other params ...
def live_feed(params: LiveFeedParams, ...):
...
from fr24.utils import static_check_signature
@static_check_signature(LiveFeedParams)
def live_feed_cli(
bbox_south: float,
bbox_north: float,
bbox_west: float,
bbox_east: float,
flight_id: int
# ... other params ...
):
""":param bbox_south: The southern latitude of the bounding box.
..."""
...
./scripts/check_signature.py
uses static analysis to:
- scan for all uses of the decorator
- for each member of the dataclass, collect all docstrings, members names and types
- for each argument of the decorated method, parse the sphinx docstring, names and types
- compare them.