Пример #1
0
def tabulate_objects(
    objects,
    fields_filter=lambda f: not f.startswith("_"),
    headers=None,
    to_local_time=True,
):
    if not headers:
        headers = [k for k in dir(objects[0]) if fields_filter(k)]

    values = []
    for o in objects:
        o_values = []
        values.append(o_values)
        for h in headers:
            value = o.__getattribute__(h)
            if to_local_time and value and isinstance(value,
                                                      datetime.datetime):
                value = pendulum.from_timestamp(_timestamp(value),
                                                "local").to_rfc822_string()
            o_values.append(value)

    return tabulate(values, headers=headers)
Пример #2
0
def parse_timestamp(value):
    """
    Parse a time string and return an aware datetime
    :param value: timestamp
    """
    return pendulum.from_timestamp(value, tz=TIMEZONE)