Some checks failed
CD Pipeline / deploy (push) Failing after 59s
- 建立 Gitea Actions CD pipeline (.gitea/workflows/cd.yaml) - 部署模式: rsync Python 檔案至 188 → docker restart (volume mount) - Dockerfile/requirements 變動時自動重建 Docker image - 部署通知: Telegram (開始/成功/失敗) - 健康檢查: https://mo.wooo.work/health (最多 5 次重試) - 同步最新 CLAUDE.md / ADR-008 / memory (2026-04-19) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
import logging
|
||
import sys
|
||
import os
|
||
from sqlalchemy import text
|
||
|
||
# 確保專案根目錄在 sys.path 中
|
||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||
|
||
from database.manager import DatabaseManager
|
||
from scheduler import run_edm_task
|
||
|
||
# 設定日誌
|
||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||
|
||
def reset_and_scrape():
|
||
"""
|
||
清空 promo_products 資料表並重新執行 EDM 爬蟲
|
||
"""
|
||
db = DatabaseManager()
|
||
session = db.get_session()
|
||
|
||
try:
|
||
print("="*50)
|
||
logging.info("🗑️ 正在清除所有 EDM (限時搶購) 歷史數據...")
|
||
|
||
# 執行清空指令 (SQLite 使用 DELETE,MySQL/PG 使用 TRUNCATE)
|
||
session.execute(text("DELETE FROM promo_products"))
|
||
session.commit()
|
||
|
||
logging.info("✅ 資料庫已清空。")
|
||
print("="*50)
|
||
|
||
logging.info("🚀 重新啟動 EDM 爬蟲任務 (抓取完整數據)...")
|
||
# 呼叫 scheduler.py 中的爬蟲函式
|
||
run_edm_task()
|
||
|
||
logging.info("🎉 重置與重新抓取完成!請刷新網頁查看結果。")
|
||
print("="*50)
|
||
|
||
except Exception as e:
|
||
logging.error(f"❌ 發生錯誤: {e}")
|
||
session.rollback()
|
||
finally:
|
||
session.close()
|
||
|
||
if __name__ == "__main__":
|
||
# 再次確認提示
|
||
confirm = input("⚠️ 警告:這將刪除所有「限時搶購」的歷史價格紀錄,確定要繼續嗎?(y/n): ")
|
||
if confirm.lower() == 'y':
|
||
reset_and_scrape()
|
||
else:
|
||
print("已取消操作。")
|