add humanize

This commit is contained in:
Tomáš Mládek 2021-02-11 02:14:06 +01:00
parent e658e01911
commit 852cfaed2a
3 changed files with 24 additions and 2 deletions

View file

@ -12,6 +12,7 @@ from time import sleep
from typing import List, Optional
import click
import humanize
import routeros_api
from jinja2 import Environment, select_autoescape, FileSystemLoader
@ -192,7 +193,12 @@ def run_forever(address: str, period: int, ssid: str, output: str):
leaderboard_entry = namedtuple('leaderboard_entry', ('name', 'total'))
leaderboard = []
for mac, minutes in leaderboard_tmp.items():
leaderboard.append(leaderboard_entry(mac_to_hostname.get(mac) or mac, timedelta(minutes=minutes)))
leaderboard.append(
leaderboard_entry(
mac_to_hostname.get(mac) or mac,
humanize.naturaldelta(timedelta(minutes=minutes))
)
)
leaderboard.sort(key=lambda l: l.total, reverse=True)
leaderboard = leaderboard[:10]

17
poetry.lock generated
View file

@ -6,6 +6,17 @@ category = "main"
optional = false
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*"
[[package]]
name = "humanize"
version = "3.2.0"
description = "Python humanize utilities"
category = "main"
optional = false
python-versions = ">=3.6"
[package.extras]
tests = ["freezegun", "pytest", "pytest-cov"]
[[package]]
name = "jinja2"
version = "2.11.3"
@ -50,13 +61,17 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
[metadata]
lock-version = "1.1"
python-versions = "^3.7"
content-hash = "d71eecd7be17faf57fdb9406d1450a3f02ad06a5551186877ec78a96aa72f46b"
content-hash = "f8e9bfe0c6df71eebe13f7e4e2f8ff195054255784a7bb431287fee1cf9e7915"
[metadata.files]
click = [
{file = "click-7.1.2-py2.py3-none-any.whl", hash = "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc"},
{file = "click-7.1.2.tar.gz", hash = "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a"},
]
humanize = [
{file = "humanize-3.2.0-py3-none-any.whl", hash = "sha256:d47d80cd47c1511ed3e49ca5f10c82ed940ea020b45b49ab106ed77fa8bb9d22"},
{file = "humanize-3.2.0.tar.gz", hash = "sha256:ab69004895689951b79f2ae4fdd6b8127ff0c180aff107856d5d98119a33f026"},
]
jinja2 = [
{file = "Jinja2-2.11.3-py2.py3-none-any.whl", hash = "sha256:03e47ad063331dd6a3f04a43eddca8a966a26ba0c5b7207a9a9e4e08f1b29419"},
{file = "Jinja2-2.11.3.tar.gz", hash = "sha256:a6d58433de0ae800347cab1fa3043cebbabe8baa9d29e668f1c768cb87a333c6"},

View file

@ -9,6 +9,7 @@ python = "^3.7"
routeros-api = "^0.17.0"
click = "^7.1.2"
Jinja2 = "^2.11.3"
humanize = "^3.2.0"
[tool.poetry.dev-dependencies]