From 00c70a23fbbfa637b8a5951901efa472fff45db0 Mon Sep 17 00:00:00 2001 From: Aevann Date: Sat, 25 Feb 2023 21:18:40 +0200 Subject: [PATCH] show number of emojis and the zip size --- files/helpers/cron.py | 9 ++++++++- files/routes/static.py | 5 ++++- files/templates/megathread_index.html | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 8e6f842ea..3d7180b84 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -1,9 +1,10 @@ import datetime import time +import os from sys import stdout from shutil import make_archive from hashlib import md5 - + import click import requests @@ -119,3 +120,9 @@ def _generate_emojis_zip(): m.update(data) cache.set('emojis_hash', m.hexdigest()) + + count = str(len(os.listdir('files/assets/images/emojis'))) + cache.set('emojis_count', count) + + size = str(int(os.stat('files/assets/emojis.zip').st_size/1024/1024)) + ' MB' + cache.set('emojis_size', size) diff --git a/files/routes/static.py b/files/routes/static.py index a4da42cbe..3761fae6c 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -205,7 +205,10 @@ def static_megathread_index(v:User): abort(404) emojis_hash = cache.get('emojis_hash') or '' - return render_template("megathread_index.html", v=v, emojis_hash=emojis_hash) + emojis_count = cache.get('emojis_count') or '' + emojis_size = cache.get('emojis_size') or '' + + return render_template("megathread_index.html", v=v, emojis_hash=emojis_hash, emojis_count=emojis_count, emojis_size=emojis_size) @app.get("/api") @limiter.limit(DEFAULT_RATELIMIT, key_func=get_ID) diff --git a/files/templates/megathread_index.html b/files/templates/megathread_index.html index 63e28c5d4..481c6214b 100644 --- a/files/templates/megathread_index.html +++ b/files/templates/megathread_index.html @@ -9,7 +9,7 @@ {%- do MEGATHREAD_INDEX.extend([ ( 'Download All Emojis', - 'Download a zip file containing all emojis.', + 'Download a zip file containing all emojis.
' ~ emojis_count ~ ' emojis - ' ~ emojis_size, 'fa-down', '#38a169', '/assets/emojis.zip?v=' + emojis_hash, ),