Files
stealergram/utils/cache.py
anti 48f486ac97 Initial commit: ULPgrammer
- Core Telegram monitoring pipeline (scraper, processor, notifier, downloaders)
- Textual TUI frontend with thread-safe event bus
- SQLite persistence, severity scoring, dedup cache
- Fixed ULP parser: handles https:// truncation, port+path URLs, semicolon separator
- Test suite: 88 tests across scorer, cache, database, processor
2026-04-02 01:58:49 -03:00

39 lines
762 B
Python

"""
cache.py — Tracks already-processed file IDs to avoid redownloading.
Persists to a simple JSON file on disk.
"""
import json
import logging
from pathlib import Path
log = logging.getLogger(__name__)
CACHE_FILE = Path("./data/cache.json")
def _load() -> set:
if not CACHE_FILE.exists():
return set()
try:
with open(CACHE_FILE, "r") as f:
return set(json.load(f))
except Exception:
return set()
def _save(seen: set) -> None:
with open(CACHE_FILE, "w") as f:
json.dump(list(seen), f)
def is_seen(file_id: int) -> bool:
return file_id in _load()
def mark_seen(file_id: int) -> None:
seen = _load()
seen.add(file_id)
_save(seen)
log.debug(f" Cached file ID {file_id}")