diff --git a/main.py b/main.py index e4663f3..70cf26e 100644 --- a/main.py +++ b/main.py @@ -64,6 +64,8 @@ def main(chat_type: int): robot.onEveryTime("09:30", robot.generateAndSendRanking) #sehuatang + robot.onEveryTime("10:00",robot.generateSehuatangPdf) + # 让机器人一直跑 robot.keepRunningAndBlockProcess() diff --git a/robot.py b/robot.py index 3b3ca6c..66d63b3 100644 --- a/robot.py +++ b/robot.py @@ -29,6 +29,7 @@ __version__ = "39.2.4.0" from message_report.process_message import process_message from message_report.write_db import write_to_db, generate_and_send_ranking from message_storage.message_to_db import archive_message +from sehuatang.shehuatang import pdf_file_path class Robot(Job): @@ -198,6 +199,8 @@ class Robot(Job): self.generateAndSendRanking() if msg.content == '聊天数据入库': self.messageCountToDB() + if msg.content == 'PDF': + self.generateSehuatangPdf() else: self.toChitchat(msg) # 闲聊 @@ -346,3 +349,12 @@ class Robot(Job): self.sendTextMsg(generate_and_send_ranking(r, self.allContacts), r) except Exception as e: self.LOG.error(f"SendRanking error:{e}") + + + def generateSehuatangPdf(self): + try: + path =pdf_file_path() + #暂时只发4K群 + self.wcf.send_file(path,"45317011307@chatroom") + except Exception as e: + self.LOG.error(f"generateSehuatangPdf error:{e}") \ No newline at end of file diff --git a/sehuatang/shehuatang.py b/sehuatang/shehuatang.py index e201cf0..f3320e9 100644 --- a/sehuatang/shehuatang.py +++ b/sehuatang/shehuatang.py @@ -175,18 +175,24 @@ def fetch_and_create_pdf(url): # 生成PDF doc.build(content) + # 获取PDF文件的绝对路径 + absolute_pdf_path = os.path.abspath(pdf_filename) + print(f"PDF saved as {absolute_pdf_path}") + + # 加密PDF + add_pdf_encryption(absolute_pdf_path) + # 关闭浏览器 driver.quit() - print(f"PDF saved as {pdf_filename}") + return absolute_pdf_path - # 加密PDF - add_pdf_encryption(pdf_filename) - return pdf_filename -def main(): +def pdf_file_path(): url = 'https://www.sehuatang.net/forum.php?mod=forumdisplay&fid=103&filter=typeid&typeid=481' - return fetch_and_create_pdf(url) + pdf_path = fetch_and_create_pdf(url) + print(f"返回的PDF文件路径:{pdf_path}") + return pdf_path if __name__ == "__main__": - main() + pdf_file_path()