feat: AI余额定时自动同步(CLI脚本+systemd每日timer+批量同步接口+前端按钮)
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
"""定时同步所有 AI 账号余额(供 systemd timer 调用)
|
||||
|
||||
用法:python scripts/sync_ai_balances.py
|
||||
依赖 .env 中的 MASTER_KEY(解密各账号 api_key)。
|
||||
"""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# 确保能导入 app 包(脚本位于 scripts/ 子目录)
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from sqlmodel import Session
|
||||
|
||||
from app.database import assets_engine, init_db
|
||||
from app.services import sync_service
|
||||
|
||||
|
||||
def main() -> int:
|
||||
init_db()
|
||||
with Session(assets_engine) as session:
|
||||
result = sync_service.sync_all_ai_balances(session)
|
||||
print(
|
||||
f"[AI余额同步] 总计 {result['total']} | 成功 {result['success']} | 失败 {result['failed']}"
|
||||
)
|
||||
for err in result["errors"]:
|
||||
print(f" - {err}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user