Download core/content.py from ABO3MR/df: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/ABO3MR/df/resolve/main/core/content.py
- Command line
-
hf download hf://spaces/ABO3MR/df/core/content.py
-
curl -L -o content.py https://huggingface.co/spaces/ABO3MR/df/resolve/main/core/content.py
1.07 kB
| """تحميل ملفات المحتوى (سطر = رد) واختيار عشوائي مع إعادة تحميل تلقائي عند تغيير الملف.""" | |
| import random | |
| from config import DATA, GAME_FILES, TAFKIK_FILE | |
| _cache = {} # filename -> (mtime_ns, size, lines) | |
| def lines(filename): | |
| p = DATA / filename | |
| if not p.exists(): | |
| return [] | |
| st = p.stat() | |
| sig = (st.st_mtime_ns, st.st_size) | |
| cached = _cache.get(filename) | |
| if cached and cached[0] == sig: | |
| return cached[1] | |
| items = [l.strip() for l in p.read_text(encoding="utf-8", errors="ignore").splitlines() if l.strip()] | |
| _cache[filename] = (sig, items) | |
| return items | |
| def clear_cache(): | |
| _cache.clear() | |
| def pick(game): | |
| fn = GAME_FILES.get(game) | |
| if not fn: | |
| return None | |
| items = lines(fn) | |
| return random.choice(items) if items else None | |
| def custom_pick(chat_custom): | |
| return random.choice(chat_custom) if chat_custom else None | |
| def tafkik_word(): | |
| items = lines(TAFKIK_FILE) | |
| return random.choice(items) if items else None | |