Spaces:
Running
Running
| import os | |
| from pathlib import Path | |
| def ensure_dir(path: str | Path): | |
| """Ensure directory exists.""" | |
| os.makedirs(path, exist_ok=True) | |
| return Path(path) | |
| # Results | |
| RESULTS_DIR = Path("results") | |
| # Data | |
| DATA_DIR = Path("data") | |
| CACHE_DIR = DATA_DIR / "cache" | |
| WATCHLIST_FILE = DATA_DIR / "watchlist.json" | |
| FILTERS_FILE = DATA_DIR / "filters.json" | |
| TOP_MOVERS_FILTERS_FILE = DATA_DIR / "top_movers_filters.json" | |
| def init_project_dirs(): | |
| """Build all required directories and pull initial config from HF.""" | |
| dirs = [RESULTS_DIR, DATA_DIR, CACHE_DIR] | |
| for d in dirs: | |
| ensure_dir(d) | |
| # Initial boot: Try to pull watchlist and filters from HF if they don't exist | |
| if not WATCHLIST_FILE.exists() or not FILTERS_FILE.exists(): | |
| try: | |
| from core.hf_manager import HFManager | |
| hf = HFManager() | |
| if not WATCHLIST_FILE.exists(): | |
| hf.download_file(WATCHLIST_FILE) | |
| if not FILTERS_FILE.exists(): | |
| hf.download_file(FILTERS_FILE) | |
| except Exception: | |
| # Silently fail if HF not available or first run | |
| pass | |