1 line
3.7 KiB
JSON
1 line
3.7 KiB
JSON
{"repo": "biyostantai/bisoi2208", "files": {"nhap.py": {"6a5eca536629c458ef733c5a41e4ab717ebee080": {"t": 1785674357.969995, "n": 3256, "h": "f46c3e8963aa775e", "c": "# -*- coding: utf-8 -*-\n\"\"\"\nNhập API key một lần, lưu vào .env local.\nChạy: python nhap.py\n\nFile .env KHÔNG bị push lên GitHub (đã có trong .gitignore).\n\"\"\"\n\nimport os\nimport re\nimport sys\nimport io\n\nif sys.platform == \"win32\":\n sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding=\"utf-8\", errors=\"replace\")\n sys.stdin = io.TextIOWrapper(sys.stdin.buffer, encoding=\"utf-8\", errors=\"replace\")\n\nENV_FILE = os.path.join(os.path.dirname(__file__), \".env\")\n\nKEYS_TO_SET = [\n (\"GPT_API_KEY\", \"OpenRouter API key (bắt đầu bằng sk-or-v1-...)\"),\n (\"DEEPSEEK_API_KEY\", \"Deepseek API key (giống OpenRouter key hoặc key riêng)\"),\n (\"OPENROUTER_API_KEY\", \"OpenRouter API key (có thể giống GPT_API_KEY)\"),\n]\n\n\ndef read_env(path):\n if not os.path.exists(path):\n return []\n with open(path, encoding=\"utf-8\") as f:\n return f.readlines()\n\n\ndef write_env(path, lines):\n with open(path, \"w\", encoding=\"utf-8\", newline=\"\\n\") as f:\n f.writelines(lines)\n\n\ndef set_key(lines, key, value):\n pattern = re.compile(r\"^\" + re.escape(key) + r\"\\s*=.*$\", re.MULTILINE)\n new_line = f\"{key}={value}\\n\"\n for i, line in enumerate(lines):\n if re.match(r\"^\" + re.escape(key) + r\"\\s*=\", line):\n lines[i] = new_line\n return lines\n # Key chưa có → thêm vào cuối\n lines.append(new_line)\n return lines\n\n\ndef main():\n print(\"=\" * 55)\n print(\" FuBot - Nhập API Key (chỉ cần làm 1 lần)\")\n print(\"=\" * 55)\n print(f\"File sẽ được lưu vào: {ENV_FILE}\")\n print(\"File này KHÔNG bị push lên GitHub.\\n\")\n\n lines = read_env(ENV_FILE)\n\n # Kiểm tra key nào đã có\n existing = {}\n for line in lines:\n m = re.match(r\"^([A-Z_]+)\\s*=\\s*(.+)$\", line.strip())\n if m:\n existing[m.group(1)] = m.group(2)\n\n changed = False\n for key, desc in KEYS_TO_SET:\n current = existing.get(key, \"\")\n masked = current[:12] + \"...\" if len(current) > 12 else current\n if current and current not in (\"\", \"your_api_key_here\", \"sk-my-secret-key-123\"):\n print(f\"[{key}] Hiện tại: {masked}\")\n ans = input(f\" Nhấn Enter để giữ nguyên, hoặc nhập key mới: \").strip()\n if not ans:\n continue\n new_val = ans\n else:\n print(f\"\\n[{key}] {desc}\")\n new_val = input(\" Nhập key: \").strip()\n if not new_val:\n print(\" Bỏ qua.\")\n continue\n\n lines = set_key(lines, key, new_val)\n changed = True\n print(f\" → Đã lưu {key}\")\n\n # Đảm bảo các config OpenRouter đúng\n lines = set_key(lines, \"GPT_BASE_URL\", \"https://openrouter.ai/api/v1\")\n lines = set_key(lines, \"GPT_MODEL\", \"deepseek/deepseek-v3.2\")\n lines = set_key(lines, \"DEEPSEEK_BASE_URL\", \"https://openrouter.ai/api/v1\")\n lines = set_key(lines, \"DEEPSEEK_MODEL\", \"deepseek/deepseek-v3.2\")\n lines = set_key(lines, \"OPENROUTER_BASE_URL\", \"https://openrouter.ai/api/v1\")\n lines = set_key(lines, \"OPENROUTER_DEEPSEEK_MODEL\", \"deepseek/deepseek-v3.2\")\n\n write_env(ENV_FILE, lines)\n print(\"\\n[OK] Đã lưu .env thành công!\")\n print(\"\\nBây giờ chạy bot: start.bat hoặc python main.py\")\n print(\"=\" * 55)\n\n\nif __name__ == \"__main__\":\n main()\n"}}}} |