import os, json, time, datetime, requests, gradio as gr # ───────────────────── 1. 기본 설정 ───────────────────── BEST_FILE, PER_PAGE = "best_games.json", 9 # ❶ 페이지당 9개 유지 # ───────────────────── 2. BEST 데이터 ──────────────────── def _init_best(): if not os.path.exists(BEST_FILE): json.dump([], open(BEST_FILE, "w"), ensure_ascii=False) def _load_best(): try: raw = json.load(open(BEST_FILE)) # URL 리스트만 반환 if isinstance(raw, list): return [u if isinstance(u, str) else u.get("url") for u in raw] return [] except Exception as e: print("BEST 로드 오류:", e) return [] def _save_best(lst): # URL 리스트 저장 try: json.dump(lst, open(BEST_FILE, "w"), ensure_ascii=False, indent=2) return True except Exception as e: print("BEST 저장 오류:", e) return False def add_url_to_best(url: str): data = _load_best() if url in data: return False data.insert(0, url) return _save_best(data) # ───────────────────── 3. 유틸 ────────────────────────── def page(lst, pg): s, e = (pg-1)*PER_PAGE, (pg-1)*PER_PAGE+PER_PAGE total = (len(lst)+PER_PAGE-1)//PER_PAGE return lst[s:e], total def process_url_for_iframe(url): # Hugging Face Spaces embed 우선 if "huggingface.co/spaces" in url: owner, name = url.rstrip("/").split("/spaces/")[1].split("/")[:2] return f"https://huggingface.co/spaces/{owner}/{name}/embed", True, [] return url, False, [] # ───────────────────── 4. 카드 그리드 HTML ─────────────── # ───────────────────── 6. HTML 그리드 ─────────────────── # ───────────────────── 6. HTML 그리드 ─────────────────── def html(cards, pg, total): if not cards: return "