# -*- coding:utf-8 -*- # author:021王掌柜 import itchat import pygame from tkinter import messagebox from itchat.content import * import time def alarm(): """播放mp3提示""" # pygame详解:music 模块 # https://blog.csdn.net/qq_41556318/article/details/86305046 pygame.mixer.init() # 初始化 pygame.mixer.music.load('./提示音.mp3') # 加载音乐 pygame.mixer.music.play() # 播放 # messagebox.showinfo('抢红包了', message='有人发红包了、快抢!') # 弹框提示 @itchat.msg_register([NOTE, TEXT], isFriendChat=False) # 检测系统注册(类型:Note通知、 isFriendChat=False:个人) def get_note(msg): """监测个人发红包""" if msg['Text'] is None: return friend_name = friend_dict.get(msg['FromUserName'], '自己') if '收到红包' in msg['Text']: print(friend_name, '************:', msg['Text'], time.strftime("%Y-%m-%d %H:%M:%S %p")) alarm() # if '已存入零钱' in msg['Text']: # pygame.mixer.music.stop() else: print(friend_name, '个人消息:', msg['Text'], time.strftime("%Y-%m-%d %X")) @itchat.msg_register([NOTE, TEXT], isGroupChat=True) # 检测系统注册(类型:Note通知、 群) def get_note(msg): """监测群发红包""" if msg['Text'] is None: return group_name = member_dict.get(msg['FromUserName'], '自己') # 获取信息群昵称 if '收到红包' in msg['Text']: print(group_name, '群************:', msg['Text'], time.strftime("%Y-%m-%d %H:%M:%S %p")) alarm() else: print(group_name, '群消息:', msg['Text'], time.strftime("%H:%M:%S %p")) # pygame.mixer.music.stop() # 结束播放音乐 # 登录 itchat.auto_login(hotReload=True) # 获取好友列表 friends = itchat.get_friends(update=True)[1:] # 从1开始,就是去除自己一个 # print(friend) print('好友数:', len(friends)) friend_dict = {} # 好友id:昵称、的字典 for f in friends: friend_dict[f['UserName']] = f['NickName'] # 保存好友头像 """ for friend in friends: img = itchat.get_head_img(userName=friend['UserName']) path = r'F:\Python\马哥Python\itchat\imgs\\' + friend["NickName"] + '.jpg' try: with open(path, 'wb') as f: f.write(img) print(f'{friend["NickName"]}:的头像已保存') except Exception as e: print(e) """ groups = itchat.get_chatrooms(update=True) # 获取所有的群 print('加入群数:', len(groups)) member_dict = {} # 群id:昵称、的字典 for g in groups: member_dict[g['UserName']] = g['NickName'] itchat.run() # 启动监听
Python 微信红包提醒脚本
最新推荐文章于 2025-01-10 15:15:06 发布