班级微信群需要每天上报由每个家长发送的健康码, 现在需要将微信群中家长发送的图片(健康码) 保存为孩子姓名(微信群里 家长群备注去掉后两位,如马云爸爸,去掉后两位,保存为马云1.jpg、马云2.jpg), 然后将所有图片保存到以当天日期命名的文件夹。
可以调用wxpy模块
wx.py
from wxpy import *
import time,os
# 微信机器人,缓存登录信息
# 如果你需要部署在服务器中,则在下面加入一个入参console_qr=True
# console_qr表示在控制台打出二维码,部署到服务器时需要加上
bot = Bot(cache_path=True)
# 当前日期文件夹
path = time.strftime("%Y%m%d", time.localtime())
path = f'D:\\{path}\\'
if not os.path.isdir(path):
os.makedirs(path)
# 监控群聊
listen_groups = '群'
bot.listen_groups = bot.groups().search(listen_groups)
if len(bot.listen_groups) < 1:
bot.listen_groups = []
print(f'未找到群名包含「{listen_groups}」的群聊!')
else:
print(f'找到群名包含「{listen_groups}」的群聊{str(len(bot.listen_groups))}个!')
def pfn(fn,num=1):
if not os.path.isfile(fn):
return fn
else:
fnlist = fn.split('.')
return pfn(fn=f'{"".join(fnlist[0:-1])}{str(num)}.{fnlist[-1]}',num=num+1)
"""群功能"""
@bot.register(chats=Group)
def group_msg(msg):
"""接收群消息"""
# 监控群聊中的图片
if msg.chat in msg.bot.listen_groups and msg.type == PICTURE :
fn = pfn(f'{path}{msg.member.name[0:-2]}.{msg.file_name.split(".")[-1]}')
print(fn)
msg.get_file(fn)
else:
pass
return None
bot.join()
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有