From 93e86fbe04068d0d4374fd326d392b2470dcd34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Mon, 3 Jan 2022 20:14:51 +0100 Subject: [PATCH] put internal stats in internal file only --- generate.py | 22 ++++++++++++++++++- templates/index.html | 50 +++++++++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/generate.py b/generate.py index af3a0a5..4ee90fc 100644 --- a/generate.py +++ b/generate.py @@ -95,8 +95,14 @@ def _is_human(lease: Lease): ) @click.option("--webhook-url", help="Webhook URL to post status changes to.") @click.option("-o", "--output", multiple=True, help="Output file.") +@click.option("--output-internal", help="Output file (with internal stats).") def run_forever( - address: str, period: int, ssid: str, output: str, webhook_url: Optional[str] + address: str, + period: int, + ssid: str, + output: str, + output_internal: Optional[str], + webhook_url: Optional[str], ): logging.basicConfig( level=logging.DEBUG, format="%(asctime)s - [%(levelname)s] %(message)s" @@ -295,9 +301,23 @@ def run_forever( last_change=last_change, log=log, leaderboard=leaderboard, + internal=False, ) file.write(out_str) + if output_internal: + with open(output_internal, "w") as file: + out_str = jinja_env.get_template("index.html").render( + now=now, + leases=registered_leases, + status=status, + last_change=last_change, + log=log, + leaderboard=leaderboard, + internal=True, + ) + file.write(out_str) + logging.info(f"Sleeping for {period} seconds.") sleep(period) diff --git a/templates/index.html b/templates/index.html index bdab1cc..eb6fd75 100644 --- a/templates/index.html +++ b/templates/index.html @@ -98,30 +98,32 @@ {% endfor %} -

Log

- - {% for entry in log %} - - - - - - {% endfor %} -
{{entry.ts.strftime("%c")}} - {% if entry.state %} - - {% else %} - OUT - {% endif %} - - {{entry.lease.display}} -
+{%if internal %} +

Log

+ + {% for entry in log %} + + + + + + {% endfor %} +
{{entry.ts.strftime("%c")}} + {% if entry.state %} + + {% else %} + OUT + {% endif %} + + {{entry.lease.display}} +
-

Leaderboard

-
    - {% for entry in leaderboard %} -
  1. {{entry.name}} ({{entry.total}})
  2. - {% endfor %} -
+

Leaderboard

+
    + {% for entry in leaderboard %} +
  1. {{entry.name}} ({{entry.total}})
  2. + {% endfor %} +
+{% endif %}