| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- # -*- coding: utf-8 -*-
- # Author : Charley
- # Python : 3.12.10
- # Date : 2026/08/04
- """得卡 DECA 已售流程——历史全量抓取(建库存量,一次性/不定时手动跑)。
- 完整管道深翻所有商家的全部历史成交:
- 商家列表 → 每商家已售(深翻) → 详情补抓 → 卡密清单 → 拆卡报告 + 视频回放。
- 写入 deca_shop_record / deca_product_record / deca_kami_record / deca_report_record。
- 从根目录运行:python sold_history_spider.py
- """
- import sys
- from loguru import logger
- from tenacity import retry, stop_after_attempt, wait_fixed
- from mysql_pool import MySQLConnectionPool
- import deca_sold_core as core
- logger.remove()
- logger.add("./logs/sold_history_{time:YYYYMMDD}.log", encoding="utf-8", rotation="00:00",
- format="[{time:YYYY-MM-DD HH:mm:ss.SSS}] {level} {message}",
- level="DEBUG", retention="7 day")
- @retry(stop=stop_after_attempt(100), wait=wait_fixed(3600), after=core.after_log)
- def main_task(log):
- """已售历史全量采集(深翻,incremental=False)。
- Args:
- log: 日志对象。
- Raises:
- RuntimeError: 数据库连接池异常时抛出以触发重试。
- """
- log.info(f"开始运行 {sys._getframe().f_code.co_name} 已售历史全量采集" + "." * 40)
- pool = MySQLConnectionPool(log=log)
- if not pool.check_pool_health():
- log.error("数据库连接池异常")
- raise RuntimeError("数据库连接池异常")
- try:
- core.run_pipeline(log, pool, incremental=False)
- except Exception as e:
- log.error(f"{sys._getframe().f_code.co_name} error: {e}")
- finally:
- log.info(f"已售历史全量采集 {sys._getframe().f_code.co_name} 运行结束" + "." * 20)
- if __name__ == "__main__":
- logger.add(sys.stderr, level="INFO") # 历史全量为手动跑,控制台同步输出
- main_task(logger)
|