From 9bee369c600fcbcfdb425e90b680bbc7eed3da6b Mon Sep 17 00:00:00 2001 From: liuwei Date: Thu, 27 Feb 2025 16:31:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E4=BA=86=E9=BB=91=E4=B8=9D?= =?UTF-8?q?=E5=9B=BE=E6=9D=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- robot.py | 21 +++++++++++++++++---- xiuren/meitu_dl.py | 24 ++++++++++++++++-------- xiuren/random_pic.py | 12 +++++++++++- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/robot.py b/robot.py index bb15aa8..3a14108 100644 --- a/robot.py +++ b/robot.py @@ -40,8 +40,8 @@ from message_report.write_db import write_to_db, generate_and_send_ranking from message_storage.message_to_db import archive_message, get_messages from message_summary.message_summary_4o import message_summary from sehuatang.shehuatang import pdf_file_path -from xiuren.meitu_dl import meitu_dowload_pic -from xiuren.random_pic import get_xiuren_pic +from xiuren.meitu_dl import meitu_dowload_pic, meitu_dowload_pub_pic, meitu_dowload_heisi_pic +from xiuren.random_pic import get_xiuren_pic, get_xiuren_heisi_pic from xiuren.xiuren_pdf import generate_pdf_from_images @@ -180,6 +180,15 @@ class Robot(Job): except Exception as e: self.LOG.error(f"图来发图出错:{e}") return True + + # 暂时只支持4K群要图 + elif q == "#黑丝图来" and msg.roomid == "45317011307@chatroom": + try: + file_path = get_xiuren_heisi_pic() + self.wcf.send_file(file_path, msg.roomid) + except Exception as e: + self.LOG.error(f"图来发图出错:{e}") + return True # 如果正则匹配到时加群指令,则从库中提取第一个群ID elif match: try: @@ -540,9 +549,13 @@ class Robot(Job): def xiu_ren_download_task(self): try: # 每天下载10组图,然后发一个帖子PDF - download_path = meitu_dowload_pic() + download_path = meitu_dowload_pub_pic() path = generate_pdf_from_images(download_path) - self.wcf.send_file(path, "45317011307@chatroom") + + download_path = meitu_dowload_heisi_pic() + path = generate_pdf_from_images(download_path) + self.wcf.send_file(path, "45317011307@chatroom") + except Exception as e: self.LOG.error(f"xiuren_dowload_pic error:{e}") diff --git a/xiuren/meitu_dl.py b/xiuren/meitu_dl.py index ef1ed0e..fa5bd8d 100644 --- a/xiuren/meitu_dl.py +++ b/xiuren/meitu_dl.py @@ -19,6 +19,7 @@ headers = { seen_posts = set() download_root = "xiuren" # 全局定义下载根目录 +download_root_heisi = 'xiuren/heisi' def fetch_posts(base_url, posts_per_batch=10): @@ -120,11 +121,10 @@ def download_image(img_url, folder_path, img_index): print(f"处理图片 {img_url} 失败: {e}") -def meitu_dowload_pic(): - base_url = "https://www.mntuce.com/" - - if not os.path.exists(download_root): - os.makedirs(download_root) +def meitu_dowload_pic(dl_path, dl_url): + base_url = dl_url + if not os.path.exists(dl_path): + os.makedirs(dl_path) print(f"开始爬取 {base_url} 的帖子...") posts = fetch_posts(base_url, 10) @@ -138,9 +138,9 @@ def meitu_dowload_pic(): print(f"\n{i}. 标题: {post['title']}") print(f" 链接: {post['url']}") - match = re.search(r'No\.(\d+)', post['title']) + match = re.search(r'[Nn][Oo]\.(\d+)', post['title']) # 支持 "No." 或 " folder_name = match.group(1) if match else f"unknown_{i}" - folder_path = os.path.join(download_root, folder_name) + folder_path = os.path.join(dl_path, folder_name) os.makedirs(folder_path, exist_ok=True) # 创建目录,exist_ok=True 避免重复创建报错 images = fetch_images(post['url']) @@ -156,5 +156,13 @@ def meitu_dowload_pic(): return download_root +def meitu_dowload_pub_pic(): + meitu_dowload_pic(download_root, "https://www.mntuce.com/") + + +def meitu_dowload_heisi_pic(): + meitu_dowload_pic(download_root_heisi, "https://www.mntuce.com/tag/%e4%b8%9d%e7%a4%be") + + if __name__ == "__main__": - meitu_dowload_pic() + meitu_dowload_heisi_pic() diff --git a/xiuren/random_pic.py b/xiuren/random_pic.py index 376d888..e1d0344 100644 --- a/xiuren/random_pic.py +++ b/xiuren/random_pic.py @@ -25,7 +25,17 @@ def get_random_file_from_dir(directory): def get_xiuren_pic(): # 使用示例 - directory = '.' # 替换为你的目录路径 + directory = 'xiuren' # 替换为你的目录路径 + random_file_path = get_random_file_from_dir(directory) + if random_file_path: + return os.path.abspath(random_file_path) + else: + return None + + +def get_xiuren_heisi_pic(): + # 使用示例 + directory = 'xiuren/heisi' # 替换为你的目录路径 random_file_path = get_random_file_from_dir(directory) if random_file_path: return os.path.abspath(random_file_path)