diff --git a/main.py b/main.py index d2629c4..ea1fbe0 100644 --- a/main.py +++ b/main.py @@ -110,9 +110,9 @@ def jobs(robot: Robot): await robot.generate_and_send_ranking() # ✅ 每天 15:30 发涩图 PDF - # @async_job.at_times(["15:30"]) - # async def sehuatang_pdf_job(): - # await robot.generate_sehuatang_pdf() + @async_job.at_times(["15:30"]) + async def sehuatang_pdf_job(): + await robot.generate_sehuatang_pdf() # ✅ 每天 01:30 下载秀人网帖子 @async_job.at_times(["01:30"]) diff --git a/requirements.txt b/requirements.txt index be40d82..4bcd239 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,4 +47,5 @@ pathlib~=1.0.1 Glances~=4.3.1 -aiofiles~=24.1.0 \ No newline at end of file +aiofiles~=24.1.0 +undetected-chromedriver~=3.5.5 \ No newline at end of file diff --git a/robot.py b/robot.py index 8459b56..a00215a 100644 --- a/robot.py +++ b/robot.py @@ -25,6 +25,7 @@ from utils.email_util import EmailSender from utils.revoke.message_auto_revoke import MessageAutoRevoke from utils.robot_cmd.robot_command import GroupBotManager, Feature, PermissionStatus from utils.sehuatang.shehuatang import pdf_file_path +from utils.sehuatang.shehuatang_undetected import pdf_file_path_undetected from utils.wechat.contact_manager import ContactManager from utils.wechat.message_to_db import MessageStorage from wechat_ipad import WechatAPIClient @@ -701,7 +702,12 @@ class Robot: async def generate_sehuatang_pdf(self): try: self.LOG.info("开始生成PDF,generate_sehuatang_pdf") - path = pdf_file_path() + try: + path = pdf_file_path() + except Exception as e: + self.LOG.error(f"generate_sehuatang_pdf error: {e}") + path = pdf_file_path_undetected() + # 暂时只发4K群 await self.send_group_file_message(path, Feature.PDF_CAPABILITY) except Exception as e: diff --git a/utils/sehuatang/sehuatang_bot.py b/utils/sehuatang/sehuatang_bot.py index c15f62a..64b77f6 100644 --- a/utils/sehuatang/sehuatang_bot.py +++ b/utils/sehuatang/sehuatang_bot.py @@ -6,6 +6,11 @@ import mysql.connector from mysql.connector import Error from selenium.webdriver.common.by import By import undetected_chromedriver as uc +if os.name == 'nt': + try: + uc.Chrome.__del__ = lambda self: None + except Exception: + pass from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from bs4 import BeautifulSoup diff --git a/utils/sehuatang/shehuatang-undetected.py b/utils/sehuatang/shehuatang_undetected.py similarity index 97% rename from utils/sehuatang/shehuatang-undetected.py rename to utils/sehuatang/shehuatang_undetected.py index 769ec99..26e01d8 100644 --- a/utils/sehuatang/shehuatang-undetected.py +++ b/utils/sehuatang/shehuatang_undetected.py @@ -3,6 +3,11 @@ import os import requests from io import BytesIO import undetected_chromedriver as uc +if os.name == 'nt': + try: + uc.Chrome.__del__ = lambda self: None + except Exception: + pass from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC @@ -166,10 +171,10 @@ def fetch_and_create_pdf(url): pass -def pdf_file_path(): +def pdf_file_path_undetected(): url = 'https://www.sehuatang.net/forum.php?mod=forumdisplay&fid=103&filter=typeid&typeid=481' return fetch_and_create_pdf(url) if __name__ == "__main__": - pdf_file_path() \ No newline at end of file + pdf_file_path_undetected()