How to use humanize - 10 common examples

To help you get started, we’ve selected a few humanize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yelp / paasta / paasta_tools / cli / cmds / status.py View on Github external
allowed_max_job_name_length=allowed_max_job_name_length,
                state=(job.get("state") or "unknown"),
                start_time=f"{str(start_time)} ({humanize.naturaltime(start_time)})",
                dashboard_url=PaastaColors.grey(f"{dashboard_url}/#/jobs/{job_id}"),
            )
        )
        if verbose and job_id in status.exceptions:
            exceptions = status.exceptions[job_id]
            root_exception = exceptions["root-exception"]
            if root_exception is not None:
                output.append(f"        Exception: {root_exception}")
                ts = exceptions["timestamp"]
                if ts is not None:
                    exc_ts = datetime.fromtimestamp(int(ts) // 1000)
                    output.append(
                        f"            {str(exc_ts)} ({humanize.naturaltime(exc_ts)})"
                    )
    if verbose and len(status.pod_status) > 0:
        output.append(f"    Pods:")
        rows: List[Union[str, Tuple[str, str, str]]] = [("Pod Name", "Host", "Phase")]
        for pod in status.pod_status:
            rows.append((pod["name"], pod["host"], pod["phase"]))
            if pod["reason"] != "":
                rows.append(PaastaColors.grey(f"  {pod['reason']}: {pod['message']}"))
        pods_table = format_table(rows)
        output.extend([f"      {line}" for line in pods_table])
    return 0
github Yelp / paasta / paasta_tools / cli / cmds / status.py View on Github external
start_time=f"{str(start_time)} ({humanize.naturaltime(start_time)})",
                dashboard_url=PaastaColors.grey(f"{dashboard_url}/#/jobs/{job_id}"),
            )
        )
        if verbose and job_id in status.exceptions:
            exceptions = status.exceptions[job_id]
            root_exception = exceptions["root-exception"]
            if root_exception is not None:
                output.append(f"        Exception: {root_exception}")
                ts = exceptions["timestamp"]
                if ts is not None:
                    exc_ts = datetime_from_utc_to_local(
                        datetime.utcfromtimestamp(int(ts) // 1000)
                    )
                    output.append(
                        f"            {str(exc_ts)} ({humanize.naturaltime(exc_ts)})"
                    )
    return 0
github Yelp / paasta / paasta_tools / cli / cmds / status.py View on Github external
)
    for job in unique_jobs:
        job_id = job["jid"]
        if verbose:
            fmt = """      {job_name: <{allowed_max_job_name_length}.{allowed_max_job_name_length}} {state: <11} {job_id} {start_time}
        {dashboard_url}"""
        else:
            fmt = "      {job_name: <{allowed_max_job_name_length}.{allowed_max_job_name_length}} {state: <11} {start_time}"
        start_time = datetime.fromtimestamp(int(job["start-time"]) // 1000)
        output.append(
            fmt.format(
                job_id=job_id,
                job_name=get_flink_job_name(job),
                allowed_max_job_name_length=allowed_max_job_name_length,
                state=(job.get("state") or "unknown"),
                start_time=f"{str(start_time)} ({humanize.naturaltime(start_time)})",
                dashboard_url=PaastaColors.grey(f"{dashboard_url}/#/jobs/{job_id}"),
            )
        )
        if verbose and job_id in status.exceptions:
            exceptions = status.exceptions[job_id]
            root_exception = exceptions["root-exception"]
            if root_exception is not None:
                output.append(f"        Exception: {root_exception}")
                ts = exceptions["timestamp"]
                if ts is not None:
                    exc_ts = datetime.fromtimestamp(int(ts) // 1000)
                    output.append(
                        f"            {str(exc_ts)} ({humanize.naturaltime(exc_ts)})"
                    )
    if verbose and len(status.pod_status) > 0:
        output.append(f"    Pods:")
github jmoiron / humanize / tests / test_time.py View on Github external
def test_naturaldelta_minimum_unit_explicit(minimum_unit, seconds, expected):
    # Arrange
    delta = dt.timedelta(seconds=seconds)

    # Act / Assert
    assert humanize.naturaldelta(delta, minimum_unit=minimum_unit) == expected
github jmoiron / humanize / tests / test_time.py View on Github external
def nd_nomonths(d):
    return humanize.naturaldelta(d, months=False)
github ga4gh / ga4gh-server / tests / utils.py View on Github external
def _report(self):
        delta = self.end - self.start
        timeString = humanize.time.naturaldelta(delta)
        print("Finished in {} ({} seconds)".format(timeString, delta))
github ga4gh / ga4gh-schemas / tests / utils.py View on Github external
def _updateDisplay(self):
        fileName = self._getFileNameDisplayString()

        # TODO contentLength seems to slightly under-report how many bytes
        # we have to download... hence the min functions
        percentage = min(self.bytesWritten / self.contentLength, 1)
        numerator = humanize.filesize.naturalsize(
            min(self.bytesWritten, self.contentLength))
        denominator = humanize.filesize.naturalsize(
            self.contentLength)

        displayString = "{}   {:<6.2%} ({:>9} / {:<9})\r"
        self.stream.write(displayString.format(
            fileName, percentage, numerator, denominator))
        self.stream.flush()
github jmoiron / humanize / tests / test_time.py View on Github external
def test_naturalday(test_args, expected):
    assert humanize.naturalday(*test_args) == expected
github jmoiron / humanize / tests / test_time.py View on Github external
def test_naturaldate(test_input, expected):
    assert humanize.naturaldate(test_input) == expected
github vitalk / flask-humanize / tests / test_humanize.py View on Github external
def test_use_utc(self, h):
        assert humanize.time._now == datetime.utcnow