Initial commit.

This commit is contained in:
Edward Betts 2026-03-30 19:34:46 +01:00
commit a8e0bd39e5
16 changed files with 981 additions and 0 deletions

23
cache.py Normal file
View file

@ -0,0 +1,23 @@
import json
import os
CACHE_DIR = os.path.join(os.path.dirname(__file__), 'cache')
def _cache_path(key: str) -> str:
safe_key = key.replace('/', '_').replace(' ', '_')
return os.path.join(CACHE_DIR, f"{safe_key}.json")
def get_cached(key: str):
path = _cache_path(key)
if not os.path.exists(path):
return None
with open(path) as f:
return json.load(f)
def set_cached(key: str, data) -> None:
os.makedirs(CACHE_DIR, exist_ok=True)
with open(_cache_path(key), 'w') as f:
json.dump(data, f, indent=2)