put internal stats in internal file only

This commit is contained in:
Tomáš Mládek 2022-01-03 20:14:51 +01:00
parent 2df50267ab
commit 93e86fbe04
2 changed files with 47 additions and 25 deletions

View file

@ -95,8 +95,14 @@ def _is_human(lease: Lease):
) )
@click.option("--webhook-url", help="Webhook URL to post status changes to.") @click.option("--webhook-url", help="Webhook URL to post status changes to.")
@click.option("-o", "--output", multiple=True, help="Output file.") @click.option("-o", "--output", multiple=True, help="Output file.")
@click.option("--output-internal", help="Output file (with internal stats).")
def run_forever( 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( logging.basicConfig(
level=logging.DEBUG, format="%(asctime)s - [%(levelname)s] %(message)s" level=logging.DEBUG, format="%(asctime)s - [%(levelname)s] %(message)s"
@ -295,6 +301,20 @@ def run_forever(
last_change=last_change, last_change=last_change,
log=log, log=log,
leaderboard=leaderboard, 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) file.write(out_str)

View file

@ -98,8 +98,9 @@
{% endfor %} {% endfor %}
</table> </table>
<h2>Log</h2> {%if internal %}
<table class="log"> <h2>Log</h2>
<table class="log">
{% for entry in log %} {% for entry in log %}
<tr> <tr>
<td>{{entry.ts.strftime("%c")}}</td> <td>{{entry.ts.strftime("%c")}}</td>
@ -115,13 +116,14 @@
</td> </td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
<h2>Leaderboard</h2> <h2>Leaderboard</h2>
<ol> <ol>
{% for entry in leaderboard %} {% for entry in leaderboard %}
<li>{{entry.name}} ({{entry.total}})</li> <li>{{entry.name}} ({{entry.total}})</li>
{% endfor %} {% endfor %}
</ol> </ol>
{% endif %}
</body> </body>
</html> </html>