def send_special_wishes(chatroomName='wishgroup'): itchat.get_chatrooms(update=True) chatrooms = itchat.search_chatrooms(name=chatroomName) if chatroomName is None: print(u'search result is none') else: chatroom = itchat.update_chatroom(chatroom[0]['UserName']) for friend in chatroom['MemberList']: friend = itchat.search_friends(userName=friend['UserName']) print(REAL_SINCERE_WISH % (friend['DisplayName'] or friend['NickName']), friend['UserName']) time.sleep(.5)
def get_chatroom(): global chatroom if chatroom is None: itchat.get_chatrooms(update=True) chatrooms = itchat.search_chatrooms(chatroomUserName); if chatrooms: return chatrooms[0] else: chatroom = itchat.create_chatroom(itchat.get_friends()[1:4], topic=chatroomUserName) if chatroom['BaseResponse']['ErrMsg'] == '': chatroom['UserName']=chatroomUserName return chatroom else: return chatroom
def get_chatroom(): global CHATROOM if CHATROOM is None: itchat.get_chatrooms(update=True) chatrooms = itchat.search_chatrooms(CHATROOM_NAME) if chatrooms: return chatrooms[0] else: r = itchat.create_chatroom(itchat.get_friends()[1:4], topic=CHATROOM_NAME) if r['BaseResponse']['ErrMsg'] == '': CHATROOM = {'UserName': r['ChatRoomName']} return CHATROOM else: return CHATROOM
def task(): chatroomList = itchat.get_chatrooms(False); for m in chatroomList: NickName = m['NickName'].encode('utf-8') if NickName == u'测试'.encode('utf-8'): text = u'可以定时发送了'.encode('utf-8') itchat.send(text, m['UserName'])
def get_allmembers(chatroomName=''): #chatroomName = 'wishgroup' chatroom = itchat.get_chatrooms()#name=chatroomName) # print chatroom for chatrooms in chatroom: if u'谢绝' in chatrooms['NickName']: print chatrooms print chatrooms['NickName'], chatrooms['UserName']
def get_chatrooms(update=False, contact_only=False): ''' fetch chatrooms list for options - update: if not set, local value will be returned - contact_only: if set, only starred chatrooms will be returned for results - a list of chatrooms' info dicts will be returned it is defined in components/contact.py ''' return itchat.get_chatrooms(update)
def reloadUserList(self): ''' 重载好友列表,如果程序运行期间添加了好友或群聊,通过此命令刷新 ''' self.selfUser = None self.current_user = None self.user_dict = {} self.user_count = 0 self.loadUserList(itchat.get_friends(), 'f') # 加载好友 self.loadUserList(itchat.get_chatrooms(), 'r') # 加载群聊
def get_group_chat(): # 获取群聊信息 all=itchat.get_chatrooms() for a in all: print(a) # 获取特定群聊 s=itchat.search_chatrooms(name='LitterCoder') print(s) # 获取群聊用户列表 memberlist=itchat.update_chatroom('@abcdefg1234567') print(memberlist)
def tuling_reply(msg): group = itchat.get_chatrooms(update=True) for g in group: if g['NickName'] == u"Java狼人杀交流忽悠群": from_group = g['UserName'] if msg['FromUserName'] == from_group or msg[ 'FromUserName'] == u"夜袭寡妇村": defaultReply = 'I received: ' + msg['Text'] reply = get_response(msg['Text']) return reply or defaultReply + "[I'm a robot. Talk to me. Talk on the phone]"
def login(self): itchat.auto_login(enableCmdQR=False, hotReload=False) self.chatroom_list.clear() for chatroom in itchat.get_chatrooms(): self.chatroom_list.addItem(chatroom['NickName']) self.chatroom_list.setEnabled(True) self.button.setText('导出') self.button.clicked.disconnect(self.login) self.button.clicked.connect(self.export) itchat.run(blockThread=False)
def updateRooms(self): if not self.isLogin: self.Log("请先登录!!") return self.Log("更新群聊信息中...") try: self.chatrooms = itchat.get_chatrooms() self.Log("更新群聊信息已完成!") except Exception, e: self.Log("获取群聊信息失败咯了T-T,再试一下!!")
def text_replay(msg): if 'ActualNickName' in msg: msg_from_nickname = msg['ActualNickName'] groups = itchat.get_chatrooms(update=True) for group in groups: if msg['FromUserName'] == group['UserName'] and group[ 'NickName'] == '谁是谁的谁': if check_msg(msg.text): print(u"WARNING! 这条消息涉嫌剧透,现已自动屏蔽 FROM:{}".format( group['NickName'] + '的' + msg_from_nickname))
def setfile(file): rooms = itchat.get_chatrooms(update=True) if rooms is not None: for i in rooms: uname = i['UserName'] nname = i['NickName'] itchat.send_image(file, uname) print("已发送成功到群:%s!" % nname) else: print("没有任何群!")
def after_login(): # 获得完整的群聊列表 print("完整的群聊列表如下:") print(itchat.get_chatrooms()) # 查找特定群聊 time.sleep(10) # 通过群聊名查找 chat_rooms = itchat.search_chatrooms(name='我的1') if len(chat_rooms) > 0: itchat.send_msg('测试', chat_rooms[0]['UserName'])
def SentChatRoomsMsg(name, context): itchat.get_chatrooms(update=True) iRoom = itchat.search_chatrooms(name) #add userName = '' for room in iRoom: if room['NickName'] == name: userName = room['UserName'] break itchat.send_msg(context, userName) print("发送时间:" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n" "发送到:" + name + "\n" "发送内容:" + context + "\n") # now_time = datetime.datetime.now() # print (now_time) print("*********************************************************************************") scheduler.print_jobs()
def get_group_list(itchat): ''' 获取群列表,并将其插入到 group 数据库中 :param itchat: :return: ''' room_list = itchat.get_chatrooms() room_names = [room.NickName for room in room_list] Group.create_group_from_name_list(room_names) return room_names
def SentChatRoomsMsg(name, context): #itchat.auto_login(hotReload=True) #if not (itchat.auto_login()): # print("登录失败") # return 0 itchat.auto_login() itchat.get_chatrooms(update=True) iRoom = itchat.search_chatrooms(name) #print(iRoom) userName='' for room in iRoom: if room['NickName'] == name: userName = room['UserName'] break if not userName: print('未找到该联系人') return 0 itchat.send_msg(context, userName) return 1
def group_id(): # 对于群聊消息,定义获取想要针对某个群进行机器人回复的群ID函数 groups = itchat.get_chatrooms(update=True) # print(groups) group_names = [] for i in range(len(groups)): group_name = groups[i]['NickName'] # if '中三1婚姻介绍所-8群' in group_name: group_names.append(group_name) return group_names
def sendChatroomMsg(self, roomName, context): itchat.get_chatrooms(update=True) roomNickName = roomName candidates = itchat.search_chatrooms(roomNickName) print(candidates) username = '' for candidate in candidates: if candidate['NickName'] == roomNickName: username = candidate['UserName'] break if username: sendtime = datetime.now().strftime( '%A %B %d,%Y') # Tue June 08,2018 sendtime = datetime.now().strftime('%m-%d-%Y %H:%M:%S,%A') msg = context + "Sending in " + sendtime print "Ready to send message to group %s,message as follows : \n%s" % ( roomName, msg) itchat.send_msg(msg=msg, toUserName=username)
def private_text_chat(private_msg): author = itchat.search_friends(nickName='木木九日车干')[0]['UserName'] groups = itchat.get_chatrooms(update=True) for g in groups: if g['NickName'] == '三乡没有温泉团': to_group = g['UserName'] if private_msg['FromUserName'] == to_group: #to_group if private_msg['Type'] == 'Recording': private_msg['Text']('output.mp3') dealMp3('output.mp3', 'output.wav') msg = tostr('output.wav') r_msg = sizhi_msg(msg) itchat.send_msg('傻子明:' + r_msg, toUserName=to_group) else: if private_msg.get('Text')[0] == '@': print(private_msg.get('Text')[8:]) r_msg = myrequest.search(private_msg.get('Text')[8:]) itchat.send_msg('傻子明:' + r_msg, toUserName=to_group) else: msg = private_msg['Text'] r_msg = sizhi_msg(msg) print(msg) #username = g['UserName'] itchat.send_msg('傻子明:' + r_msg, toUserName=to_group) elif private_msg['FromUserName'] == author: if private_msg['Type'] == 'Picture': #value=int(random.uniform(0,6)) #msg=['说人话','你是傻子吗','打字会不会','呵呵','哦','好的',''] return '' elif private_msg['Type'] == 'Recording': private_msg['Text']('output.mp3') dealMp3('output.mp3', 'output.wav') msg = tostr('output.wav') else: msg = private_msg['Text'] if msg == '拍照': cap = cv2.VideoCapture(0) ret, frame = cap.read() cv2.imwrite("static/img/123.png", frame) f = 'static/img/123.png' itchat.send_image(f, toUserName='******') return '' elif msg == '人脸': test.yface() g = 'static/img/456.png' itchat.send_image(g, toUserName='******') return '' elif msg[0] == '@': r_msg = myrequest.search(private_msg.get('Text')[8:]) itchat.send_msg('傻子明:' + r_msg, toUserName='******') #filehelper return '' else: r_msg = sizhi_msg(msg) itchat.send_msg('傻子明:' + r_msg, toUserName='******')
def sendmsg_allgroup(): msg = input("请输入你想发送的话:") rooms = itchat.get_chatrooms(update=True) if rooms is not None: for i in rooms: uname = i['UserName'] nname = i['NickName'] itchat.send_msg(msg, uname) print("已发送成功到群:%s!" % nname) else: print("没有任何群!")
def newWXInstance(): global friends global chatrooms userInfo = itchat.web_init() itchat.show_mobile_login() friends = itchat.get_friends(update=True) chatrooms = itchat.get_chatrooms(update=True) itchat.start_receiving() itchat.run() print('itchat end.')
def after_login(): logging.info("已登录") # 通过微信号查找好友 user_info = itchat.search_friends(wechatAccount='gt840cpui5') if len(user_info) > 0: user_name = user_info[0]['UserName'] itchat.send_msg('Bot login!', user_name) # 通过群聊名查找 logging.debug("chatroomList:", itchat.get_chatrooms()) chat_rooms = itchat.search_chatrooms(name='小家庭小故事') if len(chat_rooms) > 0:
def GetUserGroups(): global friends global chatrooms friends = itchat.get_friends(update=True) chatrooms = itchat.get_chatrooms(update=True) res = u'' for room in chatrooms: if (room[u"UserName"].startswith(u'@@')): res = res + room[u"NickName"] + u"\t$$$" + room[u"UserName"] + u"\n" return res
def getChatroomIdByName(names): chatrooms = itchat.get_chatrooms() groups = [] for name in names: group = [x for x in chatrooms if x['NickName'] == name] if len(group) != 0: groups.append(group[0]['UserName']) if len(groups) == 0: # logging.error('Cannot find the chatrooms') return None return groups
def init_monitor_groups(): chatrooms = itchat.get_chatrooms(update=False, contactOnly=False) chatroom_ids = [] chatrooms_filter = [] # print("get all>>>", chatrooms) for c in chatrooms: if c['NickName'] in config_group_nickname: chatroom_ids.append(c['UserName']) chatrooms_filter.append(c) return chatroom_ids, chatrooms_filter
def test(): import itchat itchat.auto_login(hotReload=True) groups = itchat.get_chatrooms(update=True) target_group = '' nickname = '三语股票测试' for group in groups: if group['NickName'] == nickname: target_group = group['UserName'] break itchat.send_file('dgn_t_acti_check.txt', toUserName=target_group)
def keep_concent(): itchat.auto_login(hotReload=True) myfriends = itchat.get_friends() rooms = itchat.get_chatrooms(update=True) while True: users = itchat.search_friends(name=nicheng) message = 'status login' userName = users[0]['UserName'] itchat.send(message, toUserName=userName) # myfriends["UserName"]) print('status login success!') time.sleep(60 * 5)
def sendfile_allgroup(): file = input("请输入你想发送的文件的路径如'E:/hello/桂东.html'(记得加引号!!!):") rooms = itchat.get_chatrooms(update=True) if rooms is not None: for i in rooms: uname = i['UserName'] nname = i['NickName'] itchat.send_image(file, uname) print("已发送成功到群:%s!" % nname) else: print("没有任何群!")
def group_reply(msg): group = itchat.get_chatrooms(update=True) for g in group: if g['NickName']== u'动物世界': if msg['FromUserName'] == g['UserName']: print g['UserName'],g['NickName'] reply = text_reply(msg) #itchat.send('%s:%s'%(msg['ActualNickName'],reply ),g['UserName']) f = pic_reply(msg) print f itchat.send("@img@%s" % f,toUserName=g['UserName'])
def get_groups(self): """获取所有群聊的名称和基本信息. 注意:群聊必须保存到通讯录才能被读取出来 """ print("获取群组信息") itchat.auto_login(hotReload=True) # 获取所有群聊 groups = itchat.get_chatrooms() with open(os.path.join("contact", "all_groups.txt"), "w") as f: for gcontact_search_pos in groups: print(g["NickName"], file=f)
def get_unchecked_member(): itchat.get_chatrooms(update=True) chatroom = itchat.search_chatrooms('100days')[0] #print(chatroom) itchat.update_chatroom(chatroom['UserName'], detailedMember=True) memberList = [] print(datetime.datetime.now().strftime("%Y-%m-%d")) unchecked_users = User.select().where( User.updated_date < datetime.datetime.now().strftime("%Y-%m-%d")) for user in unchecked_users: print(user.username) print([ m for m in chatroom['MemberList'] if m['UserName'] == user.openid ]) if [m for m in chatroom['MemberList'] if m['UserName'] == user.openid]: memberList.append([ m for m in chatroom['MemberList'] if m['UserName'] == user.openid ][0]) return memberList
def getChatRoomId(self, nickname): # 获取群聊的username groupContent = itchat.get_chatrooms() # log.debug(groupContent) chatroomid = '' for item in groupContent: if item['NickName'] == nickname: chatroomid = item['UserName'] log.info('get chat room “%s” id successfully的ID:%s' % (nickname, chatroomid)) return chatroomid
def get_groups(self): lst_group = [] groups = itchat.get_chatrooms() for group_ in groups: user = {} user["NickName"] = group_["NickName"] user["UserName"] = group_["UserName"] # user["HeadImg"] = itchat.get_head_img(chatroomUserName=user["UserName"]) lst_group.append(user) return lst_group
def __init__(self): self.user_count = 0 self.selfUser = None self.user_dict = {} self.current_user = None # 当前正在聊天的用户 self.room_dept = -1 # 用于记录好友和群聊的分界点id self.cmd = Cmd(self) # 初始化一个命令管理器, 此命令管理器管理所有的命令 itchat.auto_login(hotReload=True,enableCmdQR = 2,exitCallback=itchat.logout) #登录并记录登录状态 threading.Thread(target=itchat.run).start() # 线程启动run实现 self.loadUserList(itchat.get_friends(),'f') # 加载好友 self.loadUserList(itchat.get_chatrooms(),'r') # 加载群聊
def update_groups(): global groups tmp = [] for group in itchat.get_chatrooms(update=True): if group['NickName'].startswith(PREFIX) and block_groups.get(group['NickName']) is None: tmp.append(group['UserName']) itchat.get_batch_contract(group['UserName']) groups = tmp print(groups) print(time.time()) thread = threading.Timer(55, update_groups) thread.daemon = True thread.start()
def __init__(self, roomNicks): global wxRooms, myUid itchat.auto_login(hotReload=True, enableCmdQR=2, exitCallback=wechatExit) all_rooms = itchat.get_chatrooms(update=True) for r in all_rooms: if r['NickName'] in roomNicks: wxRooms[r['UserName']] = r['NickName'] wxRoomNicks[r['NickName']] = r['UserName'] logger.info('Room {} found.'.format(r["NickName"])) else: logger.info('{}: {}'.format(r['UserName'], r['NickName'])) friends = itchat.get_friends() myUid = friends[0]["UserName"]
def findgroups(friendname): chatrooms = itchat.get_chatrooms(update=True) # chatrooms = itchat.search_chatrooms(chatroomUserName); # chatrooms = pd.DataFrame(chatrooms) #print(chatrooms.iloc[0]) if chatrooms is not None: # print chatrooms pass else: print("Cannot find the chatroom: ") return None friends = itchat.search_friends(name=friendname, userName=None, remarkName=None, nickName=None,wechatAccount=None) for friend in friends: for chatroom in chatrooms: print chatroom if friend in chatroom['self']: print 'friend ' + friend['username'] + ' is in ' + chatroom['username'] print friend
#coding=utf-8 import itchat, time itchat.auto_login(enableCmdQR=2, hotReload=True) wish = 'Good afternoon %s' itchat.get_chatrooms(update=True) def get_allmembers(chatroomName=''): #chatroomName = 'wishgroup' chatroom = itchat.get_chatrooms()#name=chatroomName) # print chatroom for chatrooms in chatroom: if u'谢绝' in chatrooms['NickName']: print chatrooms print chatrooms['NickName'], chatrooms['UserName'] # if chatroom is None or len(chatroom) == 0: # pass # print(u'No chat is found: ' + chatroomName) ''' else: chatroom = itchat.update_chatroom(chatroom[0]['UserName']) for friend in chatroom['MemberList']: # print("friend name is : %s " % (friend['DisplayName'] or friend['NickName']))#, friend['UserName']) friend = itchat.search_friends(userName=friend['UserName']) if friend is not None: pass # print(wish % (friend['DisplayName'] or friend['NickName']))#, friend['UserName']) time.sleep(.5) ''' #get_allmembers(u'Vanderbilt Global') get_allmembers()
def run(): while True: send_type = show() if send_type == 1: getshow = show_type() if getshow == 1: sendmsg_onegroup() elif getshow == 2: print("你确定要发送到以下这些群吗?") rooms = itchat.get_chatrooms(update=True) for i in rooms: print(i['NickName']) ans = input("yes/no?") if ans == "yes": sendmsg_allgroup() else: run() elif getshow == 3: break else: print("您输入的数字不在范围内!请重新输入1-3内的数字:") show_type() elif send_type == 2: getshow = show_type() if getshow == 1: sendimage_onegroup() elif getshow == 2: print("你确定要发送到以下这些群吗?") rooms = itchat.get_chatrooms(update=True) for i in rooms: print(i['NickName']) ans = input("yes/no?") if ans == "yes": sendimage_allgroup() else: run() elif getshow == 3: break else: print("您输入的数字不在范围内!请重新输入1-3内的数字:") show_type() elif send_type == 3: getshow = show_type() if getshow == 1: sendfile_onegroup() elif getshow == 2: print("你确定要发送到以下这些群吗?") rooms = itchat.get_chatrooms(update=True) for i in rooms: print(i['NickName']) ans = input("yes/no?") if ans == "yes": sendfile_allgroup() else: run() elif getshow == 3: break else: print("您输入的数字不在范围内!请重新输入1-3内的数字:") show_type() elif send_type == 4: break else: print("您输入的数字不在范围内!请重新输入1-4内的数字:") show()
def run_all(): while True: global MSG global IMG global FILE sendtype = show_login() result = False if sendtype == 1: result = login_normal() elif sendtype == 2: result = login_vip() else: break if result == True: print("登陆成功!") print("请准备扫描登陆微信") itchat.auto_login(hotReload=True) print("登陆微信成功!您有以下这些群:") rooms = itchat.get_chatrooms(update=True) for i in rooms: print(i['NickName']) getans = show_time() if getans == 1: time_set = input("请输入一个间隔时间:如3即从先在开始每3小时自动发送") get_type = show() if get_type == 1: MSG = input("请输入您要发送的文字:") print("准备发送中。。。") def msgset(): setmsg(MSG) sched = BlockingScheduler() int_trigger = IntervalTrigger(hour=int(time_set), id="my_job") sched.add_job(msgset, int_trigger, id="my_job") print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: sched.start() except (KeyboardInterrupt, SystemExit): sched.remove_job('my_job') run_all() elif get_type == 2: IMG = input("请输入您要发送的图片路径:") print("准备发送中。。。") def imgset(): setimg(IMG) sched = BlockingScheduler() int_trigger = IntervalTrigger(hour=int(time_set), id="my_job") sched.add_job(imgset, int_trigger, id="my_job") print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: sched.start() except (KeyboardInterrupt, SystemExit): sched.remove_job('my_job') run_all() elif get_type == 3: FILE = input("请输入您要发送的文件路径:") print("准备发送中。。。") def fileset(): setfile(FILE) sched = BlockingScheduler() int_trigger = IntervalTrigger(hour=int(time_set)) sched.add_job(fileset, int_trigger, id="my_job") print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: sched.start() except (KeyboardInterrupt, SystemExit): sched.remove_job('my_job') run_all() else: break elif getans == 2: time_set = input("请输入一个准确的时间:如2018.7.10.8.20即2018年7月10日8点20分:\n") year, month, day, hour, minute = time_set.split('.')[0], time_set.split('.')[1], time_set.split('.')[2], time_set.split('.')[3], time_set.split('.')[4] get_type = show() if get_type == 1: MSG = input("请输入您要发送的文字:") print("准备发送中。。。") def msgset(): setmsg(MSG) sched = BlockingScheduler() cron_trigger = CronTrigger(year=int(year), month=int(month), day=int(day), hour=int(hour), minute=int(minute), second=0) sched.add_job(msgset, cron_trigger, id="my_job") print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: sched.start() except (KeyboardInterrupt, SystemExit): sched.remove_job('my_job') run_all() elif get_type == 2: IMG = input("请输入您要发送的图片路径:") print("准备发送中。。。") def imgset(): setimg(IMG) sched = BlockingScheduler() cron_trigger = CronTrigger(year=int(year), month=int(month), day=int(day), hour=int(hour), minute=int(minute), second=0) sched.add_job(imgset, cron_trigger, id="my_job") print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: sched.start() except (KeyboardInterrupt, SystemExit): sched.remove_job('my_job') run_all() elif get_type == 3: FILE = input("请输入您要发送的文件路径:") print("准备发送中。。。") def fileset(): setfile(FILE) sched = BlockingScheduler() cron_trigger = CronTrigger(year=int(year), month=int(month), day=int(day), hour=int(hour), minute=int(minute), second=0) sched.add_job(fileset, cron_trigger, id="my_job") print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) try: sched.start() except (KeyboardInterrupt, SystemExit): sched.remove_job('my_job') run_all() else: break elif getans == 3: run() else: break else: print("登陆失败!用户名不存在或密码错误!请重新登陆!") run_all()