Files
2026gaokaozhiyuan/check_db.py
T
simon b6df028839 v1.0.0 高考志愿门户完整修复
变更摘要:
- [fix] 清理根目录 index.html 遗留代码(questionnaire-error + retryLoad 移除)
- [fix] 副标题同步更新为自估591分 + 候选志愿546条数据校准
- [fix] 页脚注入版本号 v1.0.0
- [fix] 部署版 index.html: 取消家长标签,统一 filler-tianheng
- [fix] Dashboard 文案修正(4份→2份线上问卷)
- [fix] 清理冗余部署脚本(v1-v4归档至 archived_scripts/)
- [fix] 等效位次工具纳入 deploy 目录
- [chore] .gitignore 初始化
- [init] Git 仓库初始化
2026-06-24 13:11:34 +08:00

50 lines
1.6 KiB
Python

import paramiko, time, sqlite3, json
NAS_HOST = "100.85.152.112"
NAS_PORT = 22
NAS_USER = "simon"
NAS_PASS = "Nas82829330"
NAS_DEPLOY_PATH = "/volume1/docker/gaokao-portal"
DOCKER = f"echo '{NAS_PASS}' | sudo -S /usr/local/bin/docker"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(NAS_HOST, NAS_PORT, NAS_USER, NAS_PASS, timeout=20)
def run(cmd, desc=""):
if desc:
print(f"[{desc}]")
stdin, stdout, stderr = c.exec_command(cmd, timeout=30)
time.sleep(1)
ch = stdout.channel
out = b""
while not ch.exit_status_ready():
if ch.recv_ready():
out += ch.recv(4096)
time.sleep(0.2)
while ch.recv_ready():
out += ch.recv(4096)
return out.decode().strip()
# 检查数据库
db_path = f"{NAS_DEPLOY_PATH}/backend/data/gaokao.db"
run(f"ls -la {db_path}", "数据库文件")
# 查看问卷表内容
run(f"sqlite3 {db_path} 'SELECT id, title FROM questionnaires;'", "问卷列表")
# 如果没有,重新运行 seed
result = run(f"sqlite3 {db_path} 'SELECT COUNT(*) FROM questionnaires;'", "问卷数量")
if result.strip() == "0" or not result.strip():
print("\n数据库为空,重新运行 seed...")
run(f"cd {NAS_DEPLOY_PATH}/backend && python3 seed_data.py", "运行 seed")
# 再次检查
run(f"sqlite3 {db_path} 'SELECT id, title FROM questionnaires;'", "问卷列表")
else:
print(f"\n已有问卷: {result.strip()}")
# 查看第一份问卷的内容
result = run(f"sqlite3 {db_path} 'SELECT questions FROM questionnaires WHERE id=1;'", "问卷1内容")
print(f"\n问卷1前500字符:\n{result[:500]}")
c.close()