.ttl { margin: 0; font-size: 0.9rem; font-weight: 600; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .date { margin-top: 0; font-size: 0.7rem; color: #777; }import os, re, time, json, datetime, requests, gradio as gr # ───────────────────── 1. 기본 설정 ───────────────────── BEST_FILE, PER_PAGE = "best_games.json", 9 # ───────────────────── 2. BEST 데이터 ──────────────────── def _init_best(): if not os.path.exists(BEST_FILE): json.dump([], open(BEST_FILE, "w")) def _load_best(): try: data = json.load(open(BEST_FILE)) for it in data: if "ts" not in it: it["ts"] = int(it.get("timestamp", time.time())) return data except Exception as e: print(f"BEST 데이터 로드 오류: {e}") return [] def _save_best(data): try: json.dump(data, open(BEST_FILE, "w")) return True except Exception as e: print(f"BEST 데이터 저장 오류: {e}") return False # ───────────────────── 3. URL 추가 기능 ───────────────────── def add_url_to_best(title, url): """사용자가 제공한 URL을 BEST 목록에 추가합니다.""" try: # 현재 BEST 데이터 로드 data = _load_best() # URL이 이미 존재하는지 확인 for item in data: if item.get("url") == url: print(f"URL이 이미 존재합니다: {url}") return False # 새 항목 추가 new_item = { "title": title, "url": url, "ts": int(time.time()), "projectId": "", # 사용자가 직접 추가하므로 projectId 없음 "deploymentId": "" # 사용자가 직접 추가하므로 deploymentId 없음 } data.append(new_item) # 시간순으로 정렬 data = sorted(data, key=lambda x: x["ts"], reverse=True) # 저장 if _save_best(data): print(f"URL이 성공적으로 추가되었습니다: {url}") return True return False except Exception as e: print(f"URL 추가 오류: {str(e)}") return False # ───────────────────── 4. 페이지네이션 ─────────────────── def page(lst, pg): s = (pg-1) * PER_PAGE e = s + PER_PAGE total = (len(lst) + PER_PAGE - 1) // PER_PAGE return lst[s:e], total # ───────────────────── 5. HTML 그리드 ─────────────────── def html(cards, pg, total): if not cards: return "
{c['title']}
{date}