Skip to content

utils

TranslatedStrEnum

Bases: StrEnum

translation

Python
1
translation() -> str

Returns the Russian translation of the enumeration member.

Returns: str: The Russian translation of the enumeration member.

Source code in marketplace_apis/common/utils.py
Python
57
58
59
60
61
62
63
64
65
66
def translation(self) -> str:
    """
    Returns the Russian translation of the enumeration member.

    Returns:
    str: The Russian translation of the enumeration member.
    """
    if hasattr(self, "__translations__"):
        return self.__translations__[self.value]
    return self.name.capitalize()

datetime_to_iso

Python
1
datetime_to_iso(dt: datetime, tz: tzinfo = UTC) -> str

Converts a datetime object to an ISO formatted string, adjusting for a specified timezone.

Parameters: dt (datetime): The datetime object to convert. tz (tzinfo, optional): The timezone to adjust the datetime object to. Defaults to UTC.

Returns: str: The ISO formatted string representation of the datetime object.

Source code in marketplace_apis/common/utils.py
Python
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def datetime_to_iso(dt: datetime, tz: tzinfo = UTC) -> str:
    """
    Converts a datetime object to an ISO formatted string, adjusting for a specified
    timezone.

    Parameters:
    dt (datetime): The datetime object to convert.
    tz (tzinfo, optional): The timezone to adjust the datetime object to. Defaults to
    UTC.

    Returns:
    str: The ISO formatted string representation of the datetime object.
    """
    if dt.tzinfo != tz:
        dt = dt.astimezone(tz)
    return dt.isoformat()

dict_datetime_to_iso

Python
1
dict_datetime_to_iso(dict_: dict, tz: tzinfo = UTC)

Recursively converts all datetime objects in a dictionary to their ISO representation.

Parameters: dict_ (dict): The dictionary containing datetime objects to convert. tz (tzinfo, optional): The timezone to adjust the datetime objects to. Defaults to UTC.

Returns: None

Source code in marketplace_apis/common/utils.py
Python
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
def dict_datetime_to_iso(dict_: dict, tz: tzinfo = UTC):
    """
    Recursively converts all datetime objects in a dictionary to their ISO
    representation.

    Parameters:
    dict_ (dict): The dictionary containing datetime objects to convert.
    tz (tzinfo, optional): The timezone to adjust the datetime objects to. Defaults to
    UTC.

    Returns:
    None
    """
    for k, v in dict_.items():
        if isinstance(v, datetime):
            dict_[k] = datetime_to_iso(v, tz)
        elif isinstance(v, dict):
            dict_datetime_to_iso(v, tz)