From c58174e1afb68d305942c6b59fa2e14e79136595 Mon Sep 17 00:00:00 2001 From: LittleCoder Date: Mon, 23 Jan 2017 19:42:26 +0800 Subject: [PATCH] Fix bugs caused by strange contact return values [PR#208: lostdragon] --- docs/tutorial/tutorial1.md | 7 ++++--- itchat/components/contact.py | 14 +++++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/tutorial/tutorial1.md b/docs/tutorial/tutorial1.md index f60408d..3a49a28 100644 --- a/docs/tutorial/tutorial1.md +++ b/docs/tutorial/tutorial1.md @@ -30,7 +30,7 @@ Python与基本的网络基础都不困难,所以即使没有这方面基础 ![QRCode](http://7xrip4.com1.z0.glb.clouddn.com/ItChat%2FQRCode2.jpg?imageView/2/w/400/) -##本部分所需环境 +## 本部分所需环境 本文是这一教程的第一部分,需要配置抓包与Python环境。 @@ -59,6 +59,7 @@ Wireshark是常见的抓包软件,这里通过一些配置抓取微信网页 我们都登录过网页端微信,没有的话可以现在做一个尝试:[微信网页端](https://wx.qq.com)。 这个过程简单而言可以分为如下几步: + 1. 向服务器提供一些用于获取二维码的数据 1. 服务器返回二维码 1. 向服务器询问二维码扫描状态 @@ -313,9 +314,9 @@ print('Log in as %s'%dic['User']['NickName']) 那么做一个小练习好了,测试一下学到的东西:读取命令行的输入并发送给自己。(这部分的源码放在了文末) -##具体运用时可能遇到的难点 +## 具体运用时可能遇到的难点 -###命令行登录一段时间后无法与服务器正常交互 +### 命令行登录一段时间后无法与服务器正常交互 这是因为微信网页端存在心跳机制,一段时间不交互将会断开连接。 diff --git a/itchat/components/contact.py b/itchat/components/contact.py index 866dcf7..b4ad5d0 100644 --- a/itchat/components/contact.py +++ b/itchat/components/contact.py @@ -173,8 +173,10 @@ def update_local_friends(core, l): ''' fullList = core.memberList + core.mpList for friend in l: - utils.emoji_formatter(friend, 'NickName') - utils.emoji_formatter(friend, 'DisplayName') + if 'NickName' in friend: + utils.emoji_formatter(friend, 'NickName') + if 'DisplayName' in friend: + utils.emoji_formatter(friend, 'DisplayName') oldInfoDict = utils.search_dict_list( fullList, 'UserName', friend['UserName']) if oldInfoDict is None: @@ -223,7 +225,13 @@ def update_local_uin(core, msg): update_chatroom(core, username) newChatroomDict = utils.search_dict_list( core.chatroomList, 'UserName', username) - newChatroomDict['Uin'] = uin + if newChatroomDict is None: + newChatroomDict = utils.struct_friend_info({ + 'UserName': username, + 'Uin': uin, }) + core.chatroomList.append(newChatroomDict) + else: + newChatroomDict['Uin'] = uin elif '@' in username: update_friend(core, username) newFriendDict = utils.search_dict_list( -- GitLab