加入了黑丝图来功能
This commit is contained in:
21
robot.py
21
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}")
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user