From c2bd4d3b2c890787bce353344028c1e270c2c671 Mon Sep 17 00:00:00 2001 From: qiaoyirui0819 <3160533978@qq.com> Date: Wed, 29 Oct 2025 22:29:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8A=8A=E5=86=85=E9=83=A8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E4=BD=BF=E7=94=A8print=E8=BE=93=E5=87=BA=E7=BB=99=E7=BB=88?= =?UTF-8?q?=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/Timer_worker.py | 45 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/backend/Timer_worker.py b/backend/Timer_worker.py index 55e9c8e..9b9641b 100644 --- a/backend/Timer_worker.py +++ b/backend/Timer_worker.py @@ -117,13 +117,23 @@ class DouyinAutoScheduler: duration_s=60 ) + print("📁 开始执行抓取任务...") logging.info("📁 开始执行抓取任务...") scraper.run() + print("✅ 抖音播放量抓取任务执行成功") logging.info("✅ 抖音播放量抓取任务执行成功") # 数据抓取完成后,自动生成当日榜单 self.generate_daily_rankings() + + # 任务完成后立即显示下次执行时间 + print("🎯 任务完成,准备下次执行...") + self.show_next_run() + print("💡 定时器正在等待中,将在整点自动执行任务...") + + logging.info("🎯 任务完成,准备下次执行...") + logging.info("💡 定时器正在等待中,将在整点自动执行任务...") except Exception as e: logging.error(f"💥 执行任务时发生异常: {e}") @@ -149,10 +159,12 @@ class DouyinAutoScheduler: # 删除当天已有的榜单数据 rankings_collection.delete_many({"date": today_str}) + print(f"🗑️ 已清理 {today_str} 的旧榜单数据") logging.info(f"🗑️ 已清理 {today_str} 的旧榜单数据") # 获取今天和昨天的榜单数据进行对比 try: + print("🔄 正在生成时间轴对比榜单...") logging.info("🔄 正在生成时间轴对比榜单...") # 获取最新批次的数据 @@ -320,6 +332,11 @@ class DouyinAutoScheduler: # 统计信息 new_count = sum(1 for item in comprehensive_ranking["data"] if item["timeline_data"]["is_new"]) + print(f"✅ 时间轴对比榜单生成成功") + print(f"📊 总计 {len(comprehensive_ranking['data'])} 条记录") + print(f"🆕 新上榜 {new_count} 条") + print(f"🔄 对比基准日期: {yesterday_str}") + logging.info(f"✅ 时间轴对比榜单生成成功") logging.info(f"📊 总计 {len(comprehensive_ranking['data'])} 条记录") logging.info(f"🆕 新上榜 {new_count} 条") @@ -354,7 +371,17 @@ class DouyinAutoScheduler: jobs = schedule.get_jobs() if jobs: next_run = jobs[0].next_run - logging.info(f"⏰ 下次执行时间: {next_run}") + current_time = datetime.now() + wait_seconds = (next_run - current_time).total_seconds() + wait_minutes = int(wait_seconds // 60) + wait_hours = int(wait_minutes // 60) + remaining_minutes = wait_minutes % 60 + + print(f"💡 定时器运行中,下次执行:{next_run.strftime('%Y-%m-%d %H:%M:%S')} (还有{wait_hours}h{remaining_minutes}m)") + print(f"⏳ 距离下次执行:{wait_minutes} 分钟 ({int(wait_seconds)} 秒)") + + logging.info(f"💡 定时器运行中,下次执行:{next_run.strftime('%Y-%m-%d %H:%M:%S')} (还有{wait_hours}h{remaining_minutes}m)") + logging.info(f"⏳ 距离下次执行:{wait_minutes} 分钟 ({int(wait_seconds)} 秒)") def run_once(self): """立即执行一次""" @@ -374,20 +401,32 @@ class DouyinAutoScheduler: def start_scheduler(self): """启动定时器""" self.is_running = True + last_status_time = int(time.time()) # 设置为当前时间,1分钟后开始显示状态 + + print("🚀 抖音播放量自动抓取定时器已启动") + print("⏰ 执行时间:每小时整点执行抖音播放量抓取") + print("⏹️ 按 Ctrl+C 停止定时器") + logging.info("🚀 抖音播放量自动抓取定时器已启动") logging.info(f"⏰ 执行时间:每小时整点执行抖音播放量抓取") logging.info("⏹️ 按 Ctrl+C 停止定时器") + + # 启动时显示一次下次执行时间 + self.show_next_run() try: while self.is_running: schedule.run_pending() time.sleep(1) - # 每分钟显示一次状态 - if int(time.time()) % 600 == 0: + # 每1分钟显示一次状态 + current_time = int(time.time()) + if current_time - last_status_time >= 60: # 60秒 = 1分钟 self.show_next_run() + last_status_time = current_time except KeyboardInterrupt: + print("\n⏹️ 定时器已停止") logging.info("\n⏹️ 定时器已停止") self.is_running = False