def getroom_message(): itchat.dump_login_status() RoomList = itchat.search_chatrooms(name=name) if RoomList is None: print("%s group is not found!" % (name)) else: return RoomList[0]['UserName']
def wxRun(self): ''' 微信运行时状态 :return: ''' #itchat.run() itchat.dump_login_status()
def demo(): # 可以保持一段时间登录状态,而不用每次运行代码都要扫码登录了 itchat.auto_login(hotReload=True) itchat.dump_login_status() #遍历好友列表 friends = itchat.get_friends(update=True)[:] for friend in friends: ''' 典型属性内容如下: {'MemberList': <ContactList: []>, 'VerifyFlag': 0, 'DisplayName': '', 'EncryChatRoomId': '', 'Alias': '', 'PYQuanPin': 'Evi1hui', 'PYInitial': 'EVI1HUI', 'RemarkName': '', 'AppAccountFlag': 0, 'City': '阳泉', 'ChatRoomId': 0, 'AttrStatus': 2147715109, 'UniFriend': 0, 'OwnerUin': 0, 'Statues': 0, 'StarFriend': 0, 'ContactFlag': 3, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=654224580&username=@78606d673dcff895a468688273bb5e92862c15d9a0e8a574865785c8a0354660&skey=@crypt_cd4d9fd6_f8d94dff59afaff6b231f3f4b8aa1e15', 'Sex': 1, 'Uin': 0, 'HideInputBarFlag': 0, 'MemberCount': 0, 'Signature': '沉默的大多数', 'NickName': 'Evi1hui', 'RemarkPYQuanPin': '', 'UserName': '******', 'IsOwner': 0, 'RemarkPYInitial': '', 'KeyWord': 'wan', 'Province': '山西', 'SnsFlag': 177} ''' if friend['NickName'] == '兜哥的生活号': #print(friend['NickName']) print(friend) #发送的主键为UserName字段的值 itchat.send_msg('Nice to meet you!','@1df002b437271f75f1afd07b937801b3a7211aad221e24115fb153674ca044b7')
def sendall(msg): itchat.auto_login(hotReload=True) itchat.dump_login_status() # 遍历好友列表 friends = itchat.get_friends(update=True)[:] for friend in friends: ''' 典型属性内容如下: {'MemberList': <ContactList: []>, 'VerifyFlag': 0, 'DisplayName': '', 'EncryChatRoomId': '', 'Alias': '', 'PYQuanPin': 'Evi1hui', 'PYInitial': 'EVI1HUI', 'RemarkName': '', 'AppAccountFlag': 0, 'City': '阳泉', 'ChatRoomId': 0, 'AttrStatus': 2147715109, 'UniFriend': 0, 'OwnerUin': 0, 'Statues': 0, 'StarFriend': 0, 'ContactFlag': 3, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=654224580&username=@78606d673dcff895a468688273bb5e92862c15d9a0e8a574865785c8a0354660&skey=@crypt_cd4d9fd6_f8d94dff59afaff6b231f3f4b8aa1e15', 'Sex': 1, 'Uin': 0, 'HideInputBarFlag': 0, 'MemberCount': 0, 'Signature': '沉默的大多数', 'NickName': 'Evi1hui', 'RemarkPYQuanPin': '', 'UserName': '******', 'IsOwner': 0, 'RemarkPYInitial': '', 'KeyWord': 'wan', 'Province': '山西', 'SnsFlag': 177} ''' UserName=friend['UserName'] NickName=friend['NickName'] City=friend['City'] #print("UserName:%s NickName:%s City:%s" % (UserName,NickName,City)) # 发送的主键为UserName字段的值 text="hi %s,%s" %(NickName,msg) # 休眠10秒 time.sleep(10) print(text) itchat.send_msg(text, UserName)
def relogin(fileDir): # global lock sleepTime = 1200 while (True): lock.acquire() print("lock acquire") if os.path.exists(fileDir) and time.time() - os.path.getatime( fileDir) > 2 * sleepTime: rm(fileDir) print("................loading....................") if itchat.load_login_status(fileDir): pass else: if cmdQR: itchat.login(enableCmdQR=2) else: picDir = 'QR.png' itchat.login(picDir=picDir) # to modified: miniconda3/lib/python3.7/site-packages/itchat/utils.py itchat.dump_login_status(fileDir=fileDir) print("................load success ................") print("lock release") lock.release() time.sleep(sleepTime) pid = os.getpid() p = psutil.Process(pid) p.kill()
def wechat_send(infos): itchat.auto_login(hotReload=True) for info in infos: itchat.send( info, toUserName=itchat.search_chatrooms(name=u'自己群聊')[0]['UserName']) itchat.dump_login_status()
def demo(): # 可以保持一段时间登录状态,而不用每次运行代码都要扫码登录了 itchat.auto_login(hotReload=True) itchat.dump_login_status() #遍历好友列表 friends = itchat.get_friends(update=True)[:] for friend in friends: ''' 典型属性内容如下: {'MemberList': <ContactList: []>, 'VerifyFlag': 0, 'DisplayName': '', 'EncryChatRoomId': '', 'Alias': '', 'PYQuanPin': 'Evi1hui', 'PYInitial': 'EVI1HUI', 'RemarkName': '', 'AppAccountFlag': 0, 'City': '阳泉', 'ChatRoomId': 0, 'AttrStatus': 2147715109, 'UniFriend': 0, 'OwnerUin': 0, 'Statues': 0, 'StarFriend': 0, 'ContactFlag': 3, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=654224580&username=@78606d673dcff895a468688273bb5e92862c15d9a0e8a574865785c8a0354660&skey=@crypt_cd4d9fd6_f8d94dff59afaff6b231f3f4b8aa1e15', 'Sex': 1, 'Uin': 0, 'HideInputBarFlag': 0, 'MemberCount': 0, 'Signature': '沉默的大多数', 'NickName': 'Evi1hui', 'RemarkPYQuanPin': '', 'UserName': '******', 'IsOwner': 0, 'RemarkPYInitial': '', 'KeyWord': 'wan', 'Province': '山西', 'SnsFlag': 177} ''' if friend['NickName'] == '兜哥的生活号': #print(friend['NickName']) print(friend) #发送的主键为UserName字段的值 itchat.send_msg( 'Nice to meet you!', '@1df002b437271f75f1afd07b937801b3a7211aad221e24115fb153674ca044b7')
def login(): if 'Windows' in platform.system(): itchat.auto_login(enableCmdQR=1, hotReload=True) # else: itchat.auto_login(enableCmdQR=2, hotReload=True) # itchat.dump_login_status() #dump
def wc_login(): """ 登录 :return: """ itchat.auto_login(hotReload=True) itchat.dump_login_status() we_friend = itchat.get_friends(update=True)[:] friend_infos = [] for friend in we_friend[1:]: nick_name = friend["NickName"] # 好友昵称 sex = friend["Sex"] # 性别 remark_name = friend["RemarkName"] # 备注 signature = friend["Signature"] # 个性签名 province = friend["Province"] # 省份 city = friend["City"] # 城市 friend_infos.append({ 'nick_name': nick_name, 'sex': sex, 'remark_name': remark_name, 'signature': signature, 'province': province, 'city': city, }) return friend_infos
def sendall(msg): itchat.auto_login(hotReload=True) itchat.dump_login_status() # 遍历好友列表 friends = itchat.get_friends(update=True)[:] for friend in friends: ''' 典型属性内容如下: {'MemberList': <ContactList: []>, 'VerifyFlag': 0, 'DisplayName': '', 'EncryChatRoomId': '', 'Alias': '', 'PYQuanPin': 'Evi1hui', 'PYInitial': 'EVI1HUI', 'RemarkName': '', 'AppAccountFlag': 0, 'City': '阳泉', 'ChatRoomId': 0, 'AttrStatus': 2147715109, 'UniFriend': 0, 'OwnerUin': 0, 'Statues': 0, 'StarFriend': 0, 'ContactFlag': 3, 'HeadImgUrl': '/cgi-bin/mmwebwx-bin/webwxgeticon?seq=654224580&username=@78606d673dcff895a468688273bb5e92862c15d9a0e8a574865785c8a0354660&skey=@crypt_cd4d9fd6_f8d94dff59afaff6b231f3f4b8aa1e15', 'Sex': 1, 'Uin': 0, 'HideInputBarFlag': 0, 'MemberCount': 0, 'Signature': '沉默的大多数', 'NickName': 'Evi1hui', 'RemarkPYQuanPin': '', 'UserName': '******', 'IsOwner': 0, 'RemarkPYInitial': '', 'KeyWord': 'wan', 'Province': '山西', 'SnsFlag': 177} ''' UserName = friend['UserName'] NickName = friend['NickName'] City = friend['City'] #print("UserName:%s NickName:%s City:%s" % (UserName,NickName,City)) # 发送的主键为UserName字段的值 text = "hi %s,%s" % (NickName, msg) # 休眠10秒 time.sleep(10) print(text) itchat.send_msg(text, UserName)
def main(): logging.info("login") itchat.auto_login(hotReload=True, enableCmdQR=2) update_rooms_map() update_mp_map() itchat.run() itchat.dump_login_status()
def find_group_sendmsg(): # 查找群,并发送消息,已测试通过(刘凯) print 'find_group_sendmsg start' user = itchat.search_chatrooms(name=u'新技术交流小组') username = user[0]['UserName'] print username itchat.send(msg=u'test', toUserName=username) itchat.dump_login_status()
def signin(): # 查找公众号,进行签到 user = itchat.search_mps(name='Nulll.me') UserName = user[0]['UserName'] itchat.send(msg=u'3', toUserName=UserName) itchat.dump_login_status() # pickleDumps('flag', localDay) # 如果执行成功写入标致文件 exit()
def getroom_message(n): #获取群的username,对群成员进行分析需要用到 itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 RoomList = itchat.search_chatrooms(name=n) if RoomList is None: print("%s group is not found!" % (name)) else: return RoomList[0]['UserName']
def main(): try: bot_app.app.run(host='0.0.0.0', port=5490, debug=True, use_reloader=False) except KeyboardInterrupt: if itchat.useHotReload: itchat.dump_login_status()
def get_room_from_name(itchat, name): ''' 根据房间名字,返回房间对象 ''' itchat.dump_login_status() rooms = itchat.search_chatrooms(name=name) if rooms is None: return None return itchat.update_chatroom(rooms[0]['UserName'], detailedMember=True)
def get_group_members(): itchat.auto_login(hotReload=True) itchat.dump_login_status() room = itchat.search_chatrooms(name=u'xxxxxxx') gsq = itchat.update_chatroom(room[0]['UserName'], detailedMember=True) members = pd.DataFrame(gsq['MemberList']) members.to_csv('groupmembers.csv', index=False) print('Successfully saved group members information to csv file!')
def getroom_message(ChatName): # get room name # pass itchat.dump_login_status() RoomList = itchat.search_chatrooms(name=ChatName) if RoomList is None: print("没有%s群" % (ChatName)) else: return RoomList[0]["UserName"]
def getroom_message(): '''获取群的username,对群成员进行分析需要用到''' print('hahhaha') itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 RoomList = itchat.search_chatrooms(name=name) if RoomList is None: print("%s group is not found!" % (name)) else: print(RoomList[0]['UserName']) AnalyseChatFemale() return RoomList[0]['UserName']
def send(): itchat.auto_login(hotReload=True) room_name = itchat.search_chatrooms(name='3607咸鱼聚集')[0]['UserName'] itchat.send("猜拳结果:", room_name) itchat.send("@img@%s" % "Img/Res/Result.jpg", room_name) itchat.logout() itchat.run() itchat.dump_login_status()
def recall(msg): itchat.dump_login_status() myname = itchat.get_friends(update=True)[0]['UserName'] rooms = itchat.search_chatrooms(name=room_name)[0]['UserName'] username = msg['FromUserName'] if username == rooms: if msg['isAt']: text = msg['Text'] name = msg['ActualNickName'] contant = Recall.tuling(text) contant += '@%s ' % name itchat.send(contant, username)
def getGroupList(群聊名称): itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 myroom = itchat.search_chatrooms(name=群聊名称) #群聊名称 if myroom == None or len(myroom) == 0: print('没有找到群聊:' + 群聊名称) return memberList = itchat.update_chatroom(myroom[0]['UserName'], detailedMember=True) #print(memberList['MemberList']) #获取群成员昵称和群昵称 mlist = memberList['MemberList'] for it in mlist: print(it['NickName'] + ':' + it['DisplayName'])
def get_all_info_from_wechat(self): itchat.auto_login(enableCmdQR=False) # 获取群 roomslist = itchat.get_chatrooms() # 群名称 itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 myroom = itchat.search_chatrooms(name=u'小马飞单市场伙伴群') # 群聊名称 gsq = itchat.update_chatroom(myroom[0]['UserName'], detailedMember=True) l = gsq['MemberList'] for i in l: print('昵称:%s 签名:%s 性别:%s ' % (i['NickName'], i['Signature'], i['Sex']))
def get_all_info_from_wechat(self): itchat.auto_login(enableCmdQR=False) # 获取群 roomslist = itchat.get_chatrooms() # 群名称 itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 myroom = itchat.search_chatrooms(name=u'河南人力资源交流厅') # 群聊名称 gsq = itchat.update_chatroom(myroom[0]['UserName'], detailedMember=True) fileName = 'allMember' + time.strftime( '%Y-%m-%d %H', time.localtime(time.time())) + '.txt' with open(fileName, 'a') as f: for c in gsq['MemberList']: f.write(c['NickName'] + ":" + c['DisplayName'] + '\n')
def photo_joint(): # 微信登录 func_name = u"好友头像拼接" # logger.info('start %s ' % func_name) itchat.auto_login(hotReload=True) itchat.dump_login_status() friends = itchat.get_friends(update=True)[0:] user = friends[0]["UserName"] #拼凑路径 num = 0 pwd_path = os.path.abspath(os.path.dirname(os.getcwd())) desc_photos = os.path.join(pwd_path, 'res/photos') desc_full = os.path.join(pwd_path, 'res') #保存微信头像(并不是使用urllib 进行图片下载) for i in friends: # UserName 微信系统内的用户编码标识 img = itchat.get_head_img(userName=i["UserName"]) file_image = open(desc_photos + "/" + str(num) + ".jpg", 'wb') file_image.write(img) file_image.close() num += 1 ls = os.listdir(desc_photos) # 最后展示的头像都是正方形的,求出每个头像的长度 each_size = int(math.sqrt(float(640 * 640) / len(ls))) # 算出每张图片的大小多少合适 lines = int(640 / each_size) image = Image.new('RGBA', (640, 640)) # 创建640*640px的大图 x = 0 y = 0 for i in range(0, len(ls) + 1): try: img = Image.open(desc_photos + "/" + str(i) + ".jpg") except IOError: print("Error") else: # 单张图像变换大小 img = img.resize((each_size, each_size), Image.ANTIALIAS) image.paste(img, (x * each_size, y * each_size)) # 粘贴位置 x += 1 if x == lines: # 换行 x = 0 y += 1 image.save(desc_full + u"/好友头像拼接图.png") itchat.send_image(desc_full + u"/好友头像拼接图.png", 'filehelper') # 拼接完成发送给文件传输助手
def send_file_to_group(group_name, file_name): """ 发送文件到群聊 :param group_name: :param file: :return: """ itchat.dump_login_status() target_rooms = itchat.search_chatrooms(name=group_name) if target_rooms and len(target_rooms) > 0: target_rooms[0].send_file(file_name) else: print('【发送文件】抱歉,不存在这个群聊:%s' % group_name)
def save_head_photo(save_photo_dir): itchat.auto_login(hotReload=True) itchat.dump_login_status() friends = itchat.get_friends(update=True)[1:] # 采集好友头像并保存到本地 num = 0 for fri in friends: img = itchat.get_head_img(userName=fri['UserName']) img_path = os.path.join(save_photo_dir, str(num) + '.jpg') if not os.path.exists(img_path): file_image = open(img_path, 'wb') file_image.write(img) file_image.close() num += 1 print('完成好友头像保存至路径: ', save_photo_dir)
def send_word_to_group(group_name, word): """ 群聊中发送文字 :param group_name: :param content: :return: """ # 获取所有群聊 # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 itchat.dump_login_status() target_rooms = itchat.search_chatrooms(name=group_name) if target_rooms and len(target_rooms) > 0: target_rooms[0].send_msg(word) else: print('【发送文字】抱歉,不存在这个群聊:%s' % group_name)
def on_epoch_end(self, epoch, logs=None): for k in self.params['metrics']: if k in logs: self.mesg+=(k+': '+str(logs[k])[:5]+' ') self.logs_epochs.setdefault(k, []).append(logs[k]) try: itchat.send(self.mesg, toUserName='******') except: itchat.auto_login(hotReload=True,enableCmdQR=True) itchat.dump_login_status() itchat.send(self.mesg, toUserName='******') if epoch+1>=self.stopped_epoch: self.model.stop_training = True logs = logs or {} self.epoch.append(epoch) sio.savemat('logs_batches'+self.validateTitle(self.localtime)+'.mat',{'log':np.array(self.logs_batches)}) sio.savemat('logs_epochs'+self.validateTitle(self.localtime)+'.mat',{'log':np.array(self.logs_epochs)}) _thread.start_new_thread(self.get_fig,())
def spiderqun(self): # 登陆微信获取群 itchat.auto_login(enableCmdQR=False) # 获取群 roomslist = itchat.get_chatrooms() # 群名称 itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 myroom = itchat.search_chatrooms(name='健康产业同事群') # 群聊名称 gsq = itchat.update_chatroom(myroom[0]['UserName'], detailedMember=True) # print(gsq) # print(type(gsq)) with open('微信公众号粉丝信息和群信息.csv', 'a+', encoding='utf-8-sig', newline='') as f: csv_writer = csv.writer(f) for c in gsq['MemberList']: qunuser = c['NickName'] csv_writer.writerow([qunuser])
def get_info(save_file_path): ''' 获取公众号信息 :param save_file_path: :return: ''' # 避免频繁扫描二维码登录 itchat.auto_login(hotReload=True) itchat.dump_login_status() # 获取好友信息 we_friend = itchat.get_friends(update=True)[:] friends = we_friend[1:] total_numbers = len(friends) print('你的好友数量为: {}'.format(total_numbers)) friend_infos_dict = {} for fri_info in friends: for key in friend_key: if friend_infos_dict.get(key, False): friend_infos_dict[key].append(fri_info[key]) else: friend_infos_dict[key] = [fri_info[key]] # 保存信息 fri_save_file_name = os.path.join(save_file_path, '好友信息.csv') df = pd.DataFrame(friend_infos_dict) df.to_csv(fri_save_file_name, sep=',') # 获取公众号信息 mps = itchat.get_mps(update=True) mps_num = len(mps) print('你关注的公众号数量: {}'.format(mps_num)) mps_save_file_name = os.path.join(save_file_path, '公众号信息.csv') mps_dict = {} for mp in mps: for key in mps_key: if mps_dict.get(key, False): mps_dict[key].append(mp[key]) else: mps_dict[key] = [mp[key]] df = pd.DataFrame(mps_dict) df.to_csv(mps_save_file_name, sep=',', encoding='utf-8')
def get_all_info_from_wechat(self): # itchat.auto_login(enableCmdQR = False) # 获取群 roomslist = itchat.get_chatrooms() # 群名称 itchat.dump_login_status() # 显示所有的群聊信息,默认是返回保存到通讯录中的群聊 myroom = itchat.search_chatrooms(name=qun_name) # 群聊名称 gsq = itchat.update_chatroom(myroom[0]['UserName'], detailedMember=True) for i in gsq['MemberList']: # f.write('微信名:' + i['NickName'] + '|群昵称:' + i['DisplayName'] + '\n') # print('微信名:' + i['NickName'] + '|群昵称:' + i['DisplayName'] + '\n') # f.close() Wxm_list.append(i['NickName']) Ncm_list.append(i['DisplayName']) city_list.append(i['City']) dic_wxq = {'微信名': Wxm_list, '群昵称': Ncm_list,'城市':city_list} df = DataFrame(dic_wxq) df.to_excel(qun_name +'.xlsx')
def sigin(): user = itchat.search_mps(name='T00ls') UserName = user[0]['UserName'] itchat.send(msg=u'3',toUserName=UserName) itchat.dump_login_status() exit()
# -*- coding=utf-8 -*- # t00ls每日扫码微信签到脚本 import itchat def sigin(): user = itchat.search_mps(name='T00ls') UserName = user[0]['UserName'] itchat.send(msg=u'3',toUserName=UserName) itchat.dump_login_status() exit() if __name__ == '__main__': itchat.auto_login(hotReload=True) itchat.dump_login_status() sigin()