Skip to content

Utilities

Mostly used in the service.

utils ¤

Classes:

Name Description
BarePath

A path to a file without an extension.

SupportsToDict
SupportsToPolars
Ok
Err
UnwrapError

Functions:

Name Description
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
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.

intercept_logs_with_loguru

Intercepts stdlib logging to stderr with loguru.

Attributes:

Name Type Description
DEFAULT_HEADERS
IntoTimestamp TypeAlias

Unix timestamp in seconds or a datetime object.

IntoFlightId TypeAlias
SupportedFormats TypeAlias
DictT_co

The dictionary representation of an object, e.g. TypedDict.

T
E
Result TypeAlias

A type that represents either success (Ok) or failure (Err).

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, br",
    "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",
}

IntoTimestamp module-attribute ¤

IntoTimestamp: TypeAlias = Union[int, datetime]

Unix timestamp in seconds or a datetime object.

IntoFlightId module-attribute ¤

IntoFlightId: TypeAlias = Union[int, str, bytes]

SupportedFormats module-attribute ¤

SupportedFormats: TypeAlias = Literal['parquet', 'csv']

DictT_co module-attribute ¤

DictT_co = TypeVar('DictT_co', covariant=True)

The dictionary representation of an object, e.g. TypedDict.

T module-attribute ¤

T = TypeVar('T')

E module-attribute ¤

E = TypeVar('E')

Result module-attribute ¤

Result: TypeAlias = Union[Ok[T], Err[E]]

A type that represents either success (Ok) or failure (Err).

BarePath ¤

Bases: Path

A path to a file without an extension.

SupportsToDict ¤

Bases: Protocol[DictT_co]

Methods:

Name Description
to_dict

Converts the object into a dictionary.

to_dict ¤

to_dict() -> DictT_co

Converts the object into a dictionary.

SupportsToPolars ¤

Bases: Protocol

Methods:

Name Description
to_polars

Converts the object into a polars dataframe.

to_polars ¤

to_polars() -> DataFrame

Converts the object into a polars dataframe.

Ok dataclass ¤

Ok(_value: T)

Bases: Generic[T]

Methods:

Name Description
ok
err
is_ok
is_err
unwrap

Attributes:

Name Type Description
__slots__

__slots__ class-attribute instance-attribute ¤

__slots__ = ('_value',)

ok ¤

ok() -> T

err ¤

err() -> None

is_ok ¤

is_ok() -> Literal[True]

is_err ¤

is_err() -> Literal[False]

unwrap ¤

unwrap() -> T

Err dataclass ¤

Err(_value: E)

Bases: Generic[E]

Methods:

Name Description
ok
err
is_ok
is_err
unwrap

Attributes:

Name Type Description
__slots__

__slots__ class-attribute instance-attribute ¤

__slots__ = ('_value',)

ok ¤

ok() -> None

err ¤

err() -> E

is_ok ¤

is_ok() -> Literal[False]

is_err ¤

is_err() -> Literal[True]

unwrap ¤

unwrap() -> NoReturn

UnwrapError ¤

UnwrapError(err: Any, message: str)

Bases: Exception

Attributes:

Name Type Description
err Any

err property ¤

err: Any

to_unix_timestamp ¤

to_unix_timestamp(
    timestamp: IntoTimestamp | str | Literal["now"] | None,
) -> int | Literal["now"] | None

Casts timestamp-like object to a Unix timestamp in integer seconds, returning None if timestamp is None.

get_current_timestamp ¤

get_current_timestamp() -> int

Returns the current Unix timestamp in seconds.

parse_server_timestamp ¤

parse_server_timestamp(response: Response) -> int | None

to_flight_id ¤

to_flight_id(flight_id: IntoFlightId) -> int

format_bare_path ¤

format_bare_path(
    path: BarePath, format: SupportedFormats
) -> BarePath

write_table ¤

write_table(
    result: SupportsToPolars,
    file: str | Path | IO[bytes] | BarePath,
    *,
    format: SupportedFormats = "parquet",
    **kwargs: Any,
) -> None

Writes the table as the specified format via polars.

Parameters:

Name Type Description Default
file str | Path | IO[bytes] | BarePath

File path or writable file-like object. The path will be given an appropriate suffix if it is a BarePath.

required

scan_table ¤

scan_table(
    file: Path | IO[bytes] | BarePath,
    *,
    format: SupportedFormats = "parquet",
) -> LazyFrame

Reads the table as the specified format via polars.

Parameters:

Name Type Description Default
file Path | IO[bytes] | BarePath

File path or readable file-like object. The path will be given an appropriate suffix if it is a BarePath.

required

intercept_logs_with_loguru ¤

intercept_logs_with_loguru(
    level: _Level = INFO, modules: tuple[str, ...] = ()
) -> None

Intercepts stdlib logging to stderr with loguru.

Parameters:

Name Type Description Default
level _Level

The stdlib logging level to intercept.

INFO
modules tuple[str, ...]

The modules to intercept.

()