From 2f1ffe2038978bcde690e380b776074f4af8b4b1 Mon Sep 17 00:00:00 2001 From: LittleCoder Date: Mon, 20 Feb 2017 14:42:41 +0800 Subject: [PATCH] Fix contact spelling bug & fix None assignment bug [BR#226: cubesky] --- docs/intro/login.md | 2 +- itchat/components/contact.py | 8 +++++++- itchat/config.py | 2 +- itchat/storage.py | 10 +++++----- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/intro/login.md b/docs/intro/login.md index 5785d9fa..1fc120c0 100644 --- a/docs/intro/login.md +++ b/docs/intro/login.md @@ -125,7 +125,7 @@ itchat.auto_login(enableCmdQR=-1) 获取微信的所有好友信息并更新。 -* 方法名称:`get_friends`(曾用名:`get_contract`) +* 方法名称:`get_friends`(曾用名:`get_contact`) * 所需值:无 * 返回值:存储好友信息的列表 diff --git a/itchat/components/contact.py b/itchat/components/contact.py index a2072054..9ea2bebc 100644 --- a/itchat/components/contact.py +++ b/itchat/components/contact.py @@ -236,7 +236,13 @@ def update_local_uin(core, msg): update_friend(core, username) newFriendDict = utils.search_dict_list( core.memberList, 'UserName', username) - newFriendDict['Uin'] = uin + if newFriendDict is None: + newFriendDict = utils.struct_friend_info({ + 'UserName': username, + 'Uin': uin, }) + core.memberList.append(newFriendDict) + else: + newFriendDict['Uin'] = uin usernameChangedList.append(username) logger.debug('Uin fetched: %s, %s' % (username, uin)) else: diff --git a/itchat/config.py b/itchat/config.py index 1e6735fa..c0a6d673 100644 --- a/itchat/config.py +++ b/itchat/config.py @@ -1,6 +1,6 @@ import os, platform -VERSION = '1.2.25' +VERSION = '1.2.26' BASE_URL = 'https://login.weixin.qq.com' OS = platform.system() #Windows, Linux, Darwin DIR = os.getcwd() diff --git a/itchat/storage.py b/itchat/storage.py index fe49beaa..75bcac53 100644 --- a/itchat/storage.py +++ b/itchat/storage.py @@ -46,20 +46,20 @@ def search_friends(self, name=None, userName=None, remarkName=None, nickName=Non for k in ('RemarkName', 'NickName', 'Alias'): if matchDict[k] is None: del matchDict[k] if name: # select based on name - contract = [] + contact = [] for m in self.memberList: if any([m.get(k) == name for k in ('RemarkName', 'NickName', 'Alias')]): - contract.append(m) + contact.append(m) else: - contract = self.memberList[:] + contact = self.memberList[:] if matchDict: # select again based on matchDict friendList = [] - for m in contract: + for m in contact: if all([m.get(k) == v for k, v in matchDict.items()]): friendList.append(m) return copy.deepcopy(friendList) else: - return copy.deepcopy(contract) + return copy.deepcopy(contact) def search_chatrooms(self, name=None, userName=None): if userName is not None: for m in self.chatroomList: