From cbbbb9c6a6cc0aa6117ec4d669e9307411f079fc Mon Sep 17 00:00:00 2001 From: xtaodada Date: Tue, 2 Aug 2022 22:22:21 +0800 Subject: [PATCH] fix a bug --- ci.py | 2 -- main.py | 4 +++- plugins/track.py | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ci.py b/ci.py index af9747c..39cedb2 100644 --- a/ci.py +++ b/ci.py @@ -44,6 +44,4 @@ client = AsyncClient(timeout=10.0, headers=headers, follow_redirects=True) # 初始化客户端 scheduler = AsyncIOScheduler(timezone="Asia/ShangHai") -if not scheduler.running: - scheduler.start() app = Client("bot", api_id=api_id, api_hash=api_hash, bot_token=bot_token, plugins={"root": "plugins"}) diff --git a/main.py b/main.py index ceb6b28..5c03991 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,9 @@ import logging -from ci import app +from ci import app, scheduler # 日志记录 logging.basicConfig(level=logging.INFO) print("Starting...") +if not scheduler.running: + scheduler.start() app.run() diff --git a/plugins/track.py b/plugins/track.py index 8d7cce8..fe31507 100644 --- a/plugins/track.py +++ b/plugins/track.py @@ -1,5 +1,6 @@ import contextlib import traceback + from asyncio import sleep from random import uniform @@ -39,7 +40,7 @@ async def send_new(new: New): return await send_new_photo(new) if new.img_urls else await send_new_text(new) -@scheduler.scheduled_job("cron", minute="*/10", id="1") +@scheduler.scheduled_job("cron", minute="*/10", id="track") async def run_every_10_minute(): news = await get_news() news = sorted(news, key=lambda x: x.publish_time, reverse=False)