import json import os from datetime import datetime, timezone from view_common import fmt_bytes, relative_time, BLOCKLISTS_DIR from factory import e def _blocklist_stats_html(cfg): rows = '' for bl in cfg.get('dns_blocking', {}).get('blocklists', []): name = e(bl.get('name', '')) save_as = bl.get('save_as', '') bl_path = f'{BLOCKLISTS_DIR}/{save_as}' if save_as else '' try: with open(bl_path) as f: entries = sum(1 for _ in f) mtime = int(os.path.getmtime(bl_path)) size_str = fmt_bytes(os.path.getsize(bl_path)) last_refreshed = ( f'{datetime.fromtimestamp(mtime).strftime("%Y-%m-%d %H:%M")}' f' ({relative_time(mtime, datetime.now(tz=timezone.utc).timestamp())} ago)' ) except Exception: entries, size_str, last_refreshed = '-', '-', 'Never' rows += ( '
| Blocklist | ' 'Entries | ' 'Size | ' 'Last Refreshed | ' '
|---|