优化jobs

This commit is contained in:
liuwei
2025-05-20 10:26:15 +08:00
parent b44b527346
commit 3ac070c3cf

122
robot.py
View File

@@ -631,72 +631,72 @@ class Robot:
self.LOG.error(f"login_twice_auto_auth error: {e}") self.LOG.error(f"login_twice_auto_auth error: {e}")
# ============================================== 业务内容========================================================== # ============================================== 业务内容==========================================================
def set_jobs(self):
@async_job.at_times(["08:30"])
async def news_baidu_report_auto() -> None:
try:
news = News().get_baidu_news()
await self.send_group_txt_message(news, Feature.DAILY_NEWS)
except Exception as e:
self.LOG.error(f"newsBaiduReportAuto error{e}")
@async_job.at_times(["08:30"]) async def news_en_report(website, sender: str = None) -> None:
async def news_baidu_report_auto(self) -> None: try:
try: news = News().get_eng_news(website)
news = News().get_baidu_news() await self.ipad_bot.send_text_message(sender, news)
await self.send_group_txt_message(news, Feature.DAILY_NEWS) except Exception as e:
except Exception as e: self.LOG.error(f"newsEnReport error{e}")
self.LOG.error(f"newsBaiduReportAuto error{e}")
async def news_en_report(self, website, sender: str = None) -> None: # 使用装饰器标记定时任务 星期五 10:30 执行
try:
news = News().get_eng_news(website)
await self.ipad_bot.send_text_message(sender, news)
except Exception as e:
self.LOG.error(f"newsEnReport error{e}")
# 使用装饰器标记定时任务 星期五 10:30 执行 @async_job.every_weekday_time(weekday=4, time_str="10:00") # 0=周一4=周五
async def send_epic_free_games():
try:
if is_friday():
games = get_free()
await self.send_group_txt_message(games, Feature.EPIC)
except Exception as e:
self.LOG.error(f"sendEpicFreeGames error{e}")
@async_job.every_weekday_time(weekday=4, time_str="10:00") # 0=周一4=周五 # 使用装饰器标记定时任务
async def send_epic_free_games(self): @async_job.at_times(["02:30"])
try: async def message_count_to_db():
if is_friday(): try:
games = get_free() self.message_storage.write_to_db()
await self.send_group_txt_message(games, Feature.EPIC) except Exception as e:
except Exception as e: self.LOG.error(f"write_to_db error{e}")
self.LOG.error(f"sendEpicFreeGames error{e}")
# 使用装饰器标记定时任务 @async_job.at_times(["15:30"])
@async_job.at_times(["02:30"]) async def generate_sehuatang_pdf():
async def message_count_to_db(self): try:
try: self.LOG.info("开始生成PDF,generate_sehuatang_pdf")
self.message_storage.write_to_db() path = pdf_file_path()
except Exception as e: # 暂时只发4K群
self.LOG.error(f"write_to_db error{e}") await self.send_group_file_message(path, Feature.PDF_CAPABILITY)
except Exception as e:
self.LOG.error(f"generateSehuatangPdf error{e}")
@async_job.at_times(["15:30"]) @async_job.at_times(["01:30"])
async def generate_sehuatang_pdf(self): async def xiu_ren_download_task():
try: try:
self.LOG.info("开始生成PDF,generate_sehuatang_pdf") # 每天下载10组图然后发一个帖子PDF
path = pdf_file_path() meitu_dowload_pub_pic()
# 暂时只发4K群 except Exception as e:
await self.send_group_file_message(path, Feature.PDF_CAPABILITY) self.LOG.error(f"xiu_ren_download_task error{e}")
except Exception as e:
self.LOG.error(f"generateSehuatangPdf error{e}")
@async_job.at_times(["01:30"]) @async_job.at_times(["09:30"])
async def xiu_ren_download_task(self): async def generate_and_send_ranking():
try: try:
# 每天下载10组图然后发一个帖子PDF receivers = self.gbm.get_group_list()
meitu_dowload_pub_pic() if not receivers:
except Exception as e: return
self.LOG.error(f"xiu_ren_download_task error{e}") for r in receivers:
if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY) == PermissionStatus.ENABLED:
output = self.message_storage.generate_and_send_ranking(r, self.allContacts)
await self.ipad_bot.send_text_message(r, output)
except Exception as e:
self.LOG.error(f"SendRanking error{e}")
@async_job.at_times(["09:30"]) @async_job.at_times(["10:23"])
async def generate_and_send_ranking(self): async def job_test():
try: await self.ipad_bot.send_text_message("Jyunere","测试任务!")
receivers = self.gbm.get_group_list()
if not receivers:
return
for r in receivers:
if self.gbm.get_group_permission(r, Feature.DAILY_SUMMARY) == PermissionStatus.ENABLED:
output = self.message_storage.generate_and_send_ranking(r, self.allContacts)
await self.ipad_bot.send_text_message(r, output)
except Exception as e:
self.LOG.error(f"SendRanking error{e}")
@async_job.at_times(["10:23"])
async def job_test(self):
await self.ipad_bot.send_text_message("Jyunere","测试任务!")