加入4K群文件PDF文件发送功能
This commit is contained in:
2
main.py
2
main.py
@@ -64,6 +64,8 @@ def main(chat_type: int):
|
|||||||
robot.onEveryTime("09:30", robot.generateAndSendRanking)
|
robot.onEveryTime("09:30", robot.generateAndSendRanking)
|
||||||
|
|
||||||
#sehuatang
|
#sehuatang
|
||||||
|
robot.onEveryTime("10:00",robot.generateSehuatangPdf)
|
||||||
|
|
||||||
|
|
||||||
# 让机器人一直跑
|
# 让机器人一直跑
|
||||||
robot.keepRunningAndBlockProcess()
|
robot.keepRunningAndBlockProcess()
|
||||||
|
|||||||
12
robot.py
12
robot.py
@@ -29,6 +29,7 @@ __version__ = "39.2.4.0"
|
|||||||
from message_report.process_message import process_message
|
from message_report.process_message import process_message
|
||||||
from message_report.write_db import write_to_db, generate_and_send_ranking
|
from message_report.write_db import write_to_db, generate_and_send_ranking
|
||||||
from message_storage.message_to_db import archive_message
|
from message_storage.message_to_db import archive_message
|
||||||
|
from sehuatang.shehuatang import pdf_file_path
|
||||||
|
|
||||||
|
|
||||||
class Robot(Job):
|
class Robot(Job):
|
||||||
@@ -198,6 +199,8 @@ class Robot(Job):
|
|||||||
self.generateAndSendRanking()
|
self.generateAndSendRanking()
|
||||||
if msg.content == '聊天数据入库':
|
if msg.content == '聊天数据入库':
|
||||||
self.messageCountToDB()
|
self.messageCountToDB()
|
||||||
|
if msg.content == 'PDF':
|
||||||
|
self.generateSehuatangPdf()
|
||||||
else:
|
else:
|
||||||
self.toChitchat(msg) # 闲聊
|
self.toChitchat(msg) # 闲聊
|
||||||
|
|
||||||
@@ -346,3 +349,12 @@ class Robot(Job):
|
|||||||
self.sendTextMsg(generate_and_send_ranking(r, self.allContacts), r)
|
self.sendTextMsg(generate_and_send_ranking(r, self.allContacts), r)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.LOG.error(f"SendRanking error:{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}")
|
||||||
@@ -175,18 +175,24 @@ def fetch_and_create_pdf(url):
|
|||||||
# 生成PDF
|
# 生成PDF
|
||||||
doc.build(content)
|
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()
|
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'
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
pdf_file_path()
|
||||||
|
|||||||
Reference in New Issue
Block a user