Python itchat.get_chatrooms() Examples

The following are 10 code examples of itchat.get_chatrooms(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module itchat , or try the search function .
Example #1
Source File: wechat.py    From anack with GNU General Public License v3.0 6 votes vote down vote up
def SendText2ChatRoom(context, name):
    '''
    @ 发送消息到特定群聊内
    @ 备注:1.确定该群聊存在(可调用PrintChatRoomList查看)
    @      2.切记把群聊加入通讯录,否则只能显示活跃的前几个群聊
    '''
    itchat.get_chatrooms(update=True)
    iRoom = itchat.search_chatrooms(name)
    for room in iRoom:
        if room['NickName'] == name:
            userName = room['UserName']
            break
    try:
        itchat.send_msg(context, userName)
    except:
        print('warning: no this chatrooms') 
Example #2
Source File: wechat.py    From fishroom with GNU General Public License v3.0 5 votes vote down vote up
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"] 
Example #3
Source File: chat_utils.py    From spider_python with Apache License 2.0 5 votes vote down vote up
def send_to_group_chat(target_group_chat_name, file_names):
    """
    群聊
    :param target_group_chat_name:
    :param file_name:
    :return:
    """
    rooms = itchat.get_chatrooms(update=True)

    # 目标群聊对象
    target_room = None
    for room in rooms:
        group_chat_name = room.get('NickName')
        if target_group_chat_name == group_chat_name:
            target_room = room
            break

    if target_room:
        if isinstance(file_names, list):
            for file_name in file_names:
                target_room.send_image(file_name)
        else:
            target_room.send_image(file_names)

        print('发送完毕!')
    else:
        print('抱歉,不存在这个群聊') 
Example #4
Source File: WeChatAssistant.py    From WeChatAssistant with Apache License 2.0 5 votes vote down vote up
def wechat_login(self):
        try:
            itchat.auto_login(hotReload=True)
        except:
            q.put("您的微信未能正确登陆,可能是注册时间太短,微信禁止登陆网页版微信")
        chatroomsList =itchat.get_chatrooms()
        for chatroom in chatroomsList:
            group_list.append(chatroom["NickName"])
        js.writejson('groupdata.json',group_list)
        self.ShowGroup()
        self.ShowFriends()
        itchat.run() 
Example #5
Source File: wechat.py    From anack with GNU General Public License v3.0 5 votes vote down vote up
def PrintChatRoomList():
    '''
    @ 显示当前可见的群聊名
    '''
    rooms = itchat.get_chatrooms(update=True)
    for s in rooms:
        print(s['NickName']) 
Example #6
Source File: main.py    From EverydayWechat with MIT License 5 votes vote down vote up
def init_data():
    """ 初始化微信所需数据 """
    set_system_notice('登录成功')
    itchat.get_friends(update=True)  # 更新好友数据。
    itchat.get_chatrooms(update=True)  # 更新群聊数据。

    init_wechat_config()  # 初始化所有配置内容

    # 提醒内容不为空时,启动定时任务
    alarm_dict = config.get('alarm_info').get('alarm_dict')
    if alarm_dict:
        init_alarm(alarm_dict)  # 初始化定时任务

    print('初始化完成,开始正常工作。') 
Example #7
Source File: itchat_helper.py    From EverydayWechat with MIT License 5 votes vote down vote up
def get_group(group_name, update=False):
    """
    根据群组名获取群组数据
    :param group_name:str, 群组名
    :param update: bool 强制更新群组数据
    :return: obj 单个群组信息
    """
    if update: itchat.get_chatrooms(update=True)
    if not group_name: return None
    groups = itchat.search_chatrooms(name=group_name)
    if not groups: return None
    return groups[0] 
Example #8
Source File: User.py    From TouchFish with MIT License 5 votes vote down vote up
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')           # 加载群聊 
Example #9
Source File: User.py    From TouchFish with MIT License 5 votes vote down vote up
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')           # 加载群聊 
Example #10
Source File: __init__.py    From TWchat with MIT License 4 votes vote down vote up
def start():
    @itchat.msg_register([TEXT, MAP, CARD, NOTE, SHARING,PICTURE, RECORDING, ATTACHMENT, VIDEO,FRIENDS])
    def recive_contact_msg(msg):
        contact_name = get_contact_name(msg)
        try:
            wechatMain.recive_message(msg,contact_name)
            notify('TWchat',"new message from: "+contact_name)
        except AttributeError:
            pass
    
    @itchat.msg_register(TEXT, isGroupChat=True)
    def recive_group_msg(msg):
        group_name = get_group_name(msg)
        try:
            wechatMain.recive_message(msg,group_name)
            notify('TWchat',"new message from: "+group_name)
        except AttributeError:
            pass
        return   

    def on_contact_item_click(button,info):
        wechatMain.chatListBox.addNewChat(info[0],info[1])
        wechatMain.set_current_chat(info[0],info[1])
        wechatMain.chatListBox.show_chat()
        return 
    def on_chat_item_click(button,info):
        wechatMain.set_current_chat(info[0],info[1])
        return
    palette = [
        ('left', 'black', 'light gray'),
        ('right', 'black', 'dark cyan'),
        ('button', 'dark green','black'),
        ('mybg', 'black','dark cyan'),
        ('tobg', 'dark blue','light gray'),
        ('edit', 'dark cyan','black'),
        ('bg', 'dark green', 'black'),]
    print ('''
 _____  _    _  _____  _   _   ___   _____ 
|_   _|| |  | |/  __ \| | | | / _ \ |_   _|
  | |  | |  | || /  \/| |_| |/ /_\ \  | |  
  | |  | |/\| || |    |  _  ||  _  |  | |  
  | |  \  /\  /| \__/\| | | || | | |  | |  
  \_/   \/  \/  \____/\_| |_/\_| |_/  \_/  
            ''')

    wechatMain = wegui.WechatMain(palette)
    itchat.auto_login(enableCmdQR=2,hotReload=True)
    itchat.run(blockThread=False)
    userInfo =itchat.web_init()['User']
    owner_id = userInfo['UserName']
    owner_name = userInfo['NickName']
    contactlist= itchat.get_friends(update=True)
    chatlist = itchat.get_chatrooms()
    #contactlist = sorted(contactlist,key=lambda x:(x['RemarkPYInitial'],x['PYInitial']))
    contactlist = sorted(contactlist,key=lambda x:(lazy_pinyin(get_name(x))))
    wechatMain.initUserInfo(owner_id,owner_name,on_contact_item_click,on_chat_item_click,contactlist,chatlist)
    wechatMain.bind_itchat(itchat)
    wechatMain.createLoop()