This commit is contained in:
HuangHai
2026-01-12 15:31:25 +08:00
parent 2339558596
commit 8606709510
7 changed files with 109 additions and 173 deletions

View File

@@ -2,32 +2,65 @@
import sys
import os
import asyncio
"""
重复测试:
1、微信,我,设置,存储空间,漫长的等待计算,缓存,取消所有,找到小程序缓存,清除
2、手动登录新电途小程序,人工登录
如此操作后,就可以全新开始测试了,预计:
1、所有广告可以自动关闭掉
"""
# 添加当前目录到 sys.path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import logging
# 将项目根目录添加到 sys.path
project_root = os.path.dirname(os.path.abspath(__file__))
if project_root not in sys.path:
sys.path.append(project_root)
from Apps.XinDianTu.Service import XinDianTuService
from Apps.XinDianTu import Opener, Crawler, Kit
# 配置日志
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger("T1_XinDianTu")
async def run_process():
logger.info("=== 开始全流程任务 (新电途): 打开小程序 -> 爬取数据 ===")
# 步骤 0: 初始化基础服务
logger.info(">>> 步骤 0: 初始化基础服务 (数据库连接)...")
service = XinDianTuService()
await service.init_db()
def main():
print(f"🚀 正在启动新电途小程序爬虫...")
try:
from Apps.XinDianTu import Run, Kit
# 启动前清空临时目录
Kit.clear_temp_dir()
asyncio.run(Run.main())
# 步骤 1: 启动新电途小程序
logger.info(">>> 步骤 1: 启动新电途小程序...")
success = await Opener.open_mini_program()
if not success:
logger.error("❌ 无法成功打开新电途小程序,任务终止。")
return
logger.info("✅ 小程序启动成功,等待 5 秒确保界面稳定...")
await asyncio.sleep(5)
# 步骤 2: 执行爬取任务
logger.info(">>> 步骤 2: 开始执行场站爬取任务...")
success = await Crawler.main(service=service, do_cleanup=False)
if not success:
logger.error("❌ 步骤 2 爬取任务失败。")
return
except ImportError as e:
print(f"❌ 导入错误: {e}")
except KeyboardInterrupt:
print(f"\n🛑 用户手动停止了程序 (Ctrl+C)。")
logger.info("✅ 爬取任务完成!")
except Exception as e:
print(f"❌ 运行错误: {e}")
logger.error(f"❌ 运行异常: {e}")
finally:
if service:
await service.close_db()
logger.info("=== 全流程任务结束 ===")
if __name__ == "__main__":
main()
try:
asyncio.run(run_process())
except KeyboardInterrupt:
logger.info("\n🛑 用户手动停止了程序 (Ctrl+C)。")
except Exception as e:
logger.exception(f"主程序崩溃: {e}")