From 5dfb743a0179d55265b5b7aeff2040b475ca40cc Mon Sep 17 00:00:00 2001 From: liuwei Date: Tue, 20 May 2025 10:34:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95jobs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 54 +++++++++++++----------- robot.py | 123 +++++++++++++++++++++++++++---------------------------- 2 files changed, 91 insertions(+), 86 deletions(-) diff --git a/main.py b/main.py index eaf22f0..fc95238 100644 --- a/main.py +++ b/main.py @@ -50,7 +50,7 @@ def main(): else: robot.LOG.error("wechat_ipad客户端启动失败") # 注册定时任务 - # jobs(robot) + jobs(robot) # 启动Dashboard服务器 dashboard_server = None try: @@ -70,29 +70,35 @@ def main(): robot.keep_running_and_block_process() -# def jobs(robot: Robot): -# # # 每天 8:30 发送新闻 -# robot.onEveryTime("08:30", robot.news_baidu_report_auto) -# # -# # # epic -# robot.onEveryTime("10:30", robot.send_epic_free_games) -# # -# # # message report 1:数据自动从redis 转到sqllite -# robot.onEveryTime("02:30", robot.message_count_to_db) -# # # 从db中提取并发送给相关群 -# robot.onEveryTime("09:30", robot.generate_and_send_ranking) -# # -# # # sehuatang -# robot.onEveryTime("15:30", robot.generate_sehuatang_pdf) -# # -# # # 秀人网每天自动下载帖子 -# robot.onEveryTime("01:30", robot.xiu_ren_download_task) -# # -# # # 秀人网每天自动发pdf -# # robot.onEveryTime("17:30", robot.xiu_ren_pdf_send) -# -# # 每天进行二次登录检查 -# robot.onEveryHours(3, robot.login_twice_auto_auth) +def jobs(robot: Robot): + # # 每天 8:30 发送新闻 + @async_job.at_times(["08:30"]) + async def news_baidu_report_auto_job(): + await robot.news_baidu_report_auto() + + @async_job.at_times(["10:36"]) + async def test_job(): + await robot.job_test() + # # + # # # epic + # robot.onEveryTime("10:30", robot.send_epic_free_games) + # # + # # # message report 1:数据自动从redis 转到sqllite + # robot.onEveryTime("02:30", robot.message_count_to_db) + # # # 从db中提取并发送给相关群 + # robot.onEveryTime("09:30", robot.generate_and_send_ranking) + # # + # # # sehuatang + # robot.onEveryTime("15:30", robot.generate_sehuatang_pdf) + # # + # # # 秀人网每天自动下载帖子 + # robot.onEveryTime("01:30", robot.xiu_ren_download_task) + # # + # # # 秀人网每天自动发pdf + # # robot.onEveryTime("17:30", robot.xiu_ren_pdf_send) + # + # # 每天进行二次登录检查 + # robot.onEveryHours(3, robot.login_twice_auto_auth) if __name__ == "__main__": diff --git a/robot.py b/robot.py index d617b1f..e5dc31c 100644 --- a/robot.py +++ b/robot.py @@ -631,73 +631,72 @@ class Robot: 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 def news_en_report(website, sender: str = None) -> None: - 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 def news_baidu_report_auto(self) -> 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.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 def news_en_report(self, website, sender: str = None) -> None: + 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}") - # 使用装饰器标记定时任务 - @async_job.at_times(["02:30"]) - async def message_count_to_db(): - try: - self.message_storage.write_to_db() - except Exception as e: - self.LOG.error(f"write_to_db error:{e}") + # 使用装饰器标记定时任务 星期五 10:30 执行 - @async_job.at_times(["15:30"]) - async def generate_sehuatang_pdf(): - try: - self.LOG.info("开始生成PDF,generate_sehuatang_pdf") - path = pdf_file_path() - # 暂时只发4K群 - await self.send_group_file_message(path, Feature.PDF_CAPABILITY) - except Exception as e: - self.LOG.error(f"generateSehuatangPdf error:{e}") + @async_job.every_weekday_time(weekday=4, time_str="10:00") # 0=周一,4=周五 + async def send_epic_free_games(self): + 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.at_times(["01:30"]) - async def xiu_ren_download_task(): - try: - # 每天下载10组图,然后发一个帖子PDF - meitu_dowload_pub_pic() - except Exception as e: - self.LOG.error(f"xiu_ren_download_task error:{e}") + # 使用装饰器标记定时任务 + @async_job.at_times(["02:30"]) + async def message_count_to_db(self): + try: + self.message_storage.write_to_db() + except Exception as e: + self.LOG.error(f"write_to_db error:{e}") - @async_job.at_times(["09:30"]) - async def generate_and_send_ranking(): - try: - 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(["15:30"]) + async def generate_sehuatang_pdf(self): + try: + self.LOG.info("开始生成PDF,generate_sehuatang_pdf") + path = pdf_file_path() + # 暂时只发4K群 + 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(["10:30"]) - async def job_test(): - self.LOG.info("执行测试任务!") - await self.ipad_bot.send_text_message("Jyunere","测试任务!") \ No newline at end of file + @async_job.at_times(["01:30"]) + async def xiu_ren_download_task(self): + try: + # 每天下载10组图,然后发一个帖子PDF + meitu_dowload_pub_pic() + except Exception as e: + self.LOG.error(f"xiu_ren_download_task error:{e}") + + @async_job.at_times(["09:30"]) + async def generate_and_send_ranking(self): + try: + 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","测试任务!") \ No newline at end of file