Python itchat.get_friends() Examples

The following are 9 code examples of itchat.get_friends(). 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: WeChatAssistant.py    From WeChatAssistant with Apache License 2.0 6 votes vote down vote up
def ShowFriends(self):
        friendslist = itchat.get_friends(update=True)[1:]
        global frind_dict
        for frind in friendslist:
            if (frind['RemarkName'] == ''):
                frind_dict[frind['NickName']] = frind['NickName']
                try:
                    self.d_Listname.insert(END, frind['NickName'])
                except:
                    q.put("您有好友的昵称包含表情(emoji),超出此软件的显示范围,您可以修改好友备注,去除emoji,请谅解。")
            else:
                frind_dict[frind['RemarkName']] = frind['NickName']
                try:
                    self.d_Listname.insert(END, frind['RemarkName'])
                except:
                    q.put("您有好友的昵称包含表情(emoji),超出此软件的显示范围,您可以修改好友备注,去除emoji,请谅解。")
        print(frind_dict) 
Example #2
Source File: analysisFriends.py    From WechatHelper with MIT License 6 votes vote down vote up
def getFriendsInfo(self):
		try:
			itchat.auto_login(hotReload=True)
		except:
			itchat.auto_login(hotReload=True, enableCmdQR=True)
		friends = itchat.get_friends()
		friends_info = dict(
							province = self.getKeyInfo(friends, "Province"),
							city = self.getKeyInfo(friends, "City"),
							nickname = self.getKeyInfo(friends, "Nickname"),
							sex = self.getKeyInfo(friends, "Sex"),
							signature = self.getKeyInfo(friends, "Signature"),
							remarkname = self.getKeyInfo(friends, "RemarkName"),
							pyquanpin = self.getKeyInfo(friends, "PYQuanPin")
							)
		return friends_info 
Example #3
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 #4
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 #5
Source File: group_helper.py    From EverydayWechat with MIT License 5 votes vote down vote up
def get_city_by_uuid(uid):
    """
    通过用户的uid得到用户的城市
    最好是与机器人是好友关系
    """
    itchat.get_friends(update=True)
    info = itchat.search_friends(userName=uid)
    # print('info:'+str(info))
    if not info:
        return None
    city = info.city
    # print('city:'+city)
    return city 
Example #6
Source File: itchat_helper.py    From EverydayWechat with MIT License 5 votes vote down vote up
def get_friend(wechat_name, update=False):
    """
    根据用户名获取用户数据
    :param wechat_name: str 用户名
    :param update: bool 强制更新用户数据
    :return: obj 单个好友信息
    """
    if update: itchat.get_friends(update=True)
    if not wechat_name: return None
    friends = itchat.search_friends(name=wechat_name)
    if not friends: return None
    return friends[0] 
Example #7
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 #8
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 #9
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()