#!/bin/bash # FULL page-based re-sync: ALL channels, ALL entities — ZERO API calls, ZERO 风控 cd "$(dirname "$0")/.." # DB_URL:外部已设则沿用(容器里由 docker-compose 注入 MySQL);本地默认 SQLite export DB_URL="${DB_URL:-sqlite+aiosqlite:///./smoke.db}" # 可移植 python:容器里 python 在 PATH;本地 Windows 用 venv 的解释器(2026-08-21 部署阻塞点#3) if [ -f ".venv/Scripts/python.exe" ]; then PY=".venv/Scripts/python.exe" else PY="python" fi echo "==============================================" echo "$(date) === FULL PAGE-BASED RE-SYNC (NO API) ===" echo "==============================================" echo "$(date) --- 1/10 WeChat accounts ---" $PY scripts/scrape_via_page.py --entity accounts echo "$(date) --- 2/10 WA accounts ---" $PY scripts/scrape_via_page.py --entity wa-accounts echo "$(date) --- 3/10 WeChat customers ---" $PY scripts/scrape_via_page.py --entity friends --max-employees 100 echo "$(date) --- 4/10 WA customers ---" $PY scripts/scrape_via_page.py --entity wa-friends echo "$(date) --- 5/10 WeChat groups ---" $PY scripts/scrape_via_page.py --entity groups --max-employees 100 echo "$(date) --- 5b/10 WA groups ---" $PY scripts/scrape_via_page.py --entity wa-groups echo "$(date) --- 6/10 Voice calls (WeChat + WA) ---" $PY scripts/scrape_via_page.py --entity voice-calls # 语音重扫会把 record_media_hash 覆盖回 None —— 必须紧跟录音重链接 $PY -m app.sync.cli sync --entity call_recordings echo "$(date) --- 7/10 Voice clips ---" $PY scripts/scrape_via_page.py --entity voice-clips echo "$(date) --- 8/10 WeChat messages ---" $PY scripts/scrape_via_page.py --entity messages --max-conversations 99999 echo "$(date) --- 8b/10 WeChat group messages + members ---" $PY scripts/scrape_via_page.py --entity group-messages --max-conversations 99999 $PY -m scripts.backfill_group_members echo "$(date) --- 9/10 WA messages ---" $PY scripts/scrape_via_page.py --entity wa-messages --max-conversations 99999 echo "$(date) --- 9b/10 WA group messages ---" $PY scripts/scrape_via_page.py --entity wa-group-messages --max-conversations 99999 echo "$(date) --- 9c/10 Moments (员工朋友圈) ---" $PY scripts/scrape_via_page.py --entity moments echo "$(date) --- 10/10 Media download (audio+images) ---" $PY scripts/scrape_via_page.py --entity media # 11:会话日汇总全量重建(夜间自愈:绕过 upsert 钩子的写入由它纠正; # sessions/staff-chat-stats 读路径依赖此表,2026-09-03) echo "$(date) --- 11/11 Daily-stats rebuild ---" $PY -m app.sync.cli daily-stats echo "==============================================" echo "$(date) === FULL RE-SYNC COMPLETE ===" echo "==============================================" # 终局数据快照:走 app 引擎(DB_URL 可移植,SQLite/MySQL 通吃;原 sqlite3 # 直连 smoke.db 的写法在服务器 MySQL 上会炸,2026-09-03 修) $PY - <<'PYEOF' import asyncio from sqlalchemy import text from sqlalchemy.ext.asyncio import create_async_engine from app.config import get_settings TABLES = [ ("wechat accounts", "SELECT COUNT(*) FROM wechat_account"), ("whatsapp accounts", "SELECT COUNT(*) FROM whatsapp_account"), ("wechat customers", "SELECT COUNT(*) FROM customer WHERE channel='wechat'"), ("whatsapp customers", "SELECT COUNT(*) FROM customer WHERE channel='whatsapp'"), ("wechat groups", "SELECT COUNT(*) FROM chat_group WHERE channel='wechat'"), ("whatsapp groups", "SELECT COUNT(*) FROM chat_group WHERE channel='whatsapp'"), ("wechat messages", "SELECT COUNT(*) FROM message WHERE channel='wechat'"), ("whatsapp messages", "SELECT COUNT(*) FROM message WHERE channel='whatsapp'"), ("daily stats rows", "SELECT COUNT(*) FROM msg_daily_stats"), ("voice calls", "SELECT COUNT(*) FROM phone_call WHERE channel IN ('voice_call','wa_voice_call')"), ("voice clips", "SELECT COUNT(*) FROM voice_clip"), ("moments posts", "SELECT COUNT(*) FROM moments_post"), ("media files", "SELECT COUNT(*) FROM media"), ] async def main() -> None: engine = create_async_engine(get_settings().db_url) try: async with engine.connect() as conn: print() print("=== FINAL DATA SUMMARY ===") for label, sql in TABLES: n = (await conn.execute(text(sql))).scalar_one() print(f" {label:22s} {n:>6}") finally: await engine.dispose() asyncio.run(main()) PYEOF