From 2990f364834d814ab2fb0b994a7582e2c2538ecf Mon Sep 17 00:00:00 2001 From: ppwwyyxx Date: Mon, 9 Nov 2015 10:48:41 -0500 Subject: [PATCH] fix when contacts are deleted --- README.md | 10 +++++----- wechat/parser.py | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 787b71d..f512218 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ ## 导出安卓微信聊天数据 -WeChat(微信), as the most popular mobile IM app in China, failed to allow users to export well-formatted chat history. -This tool can parse and export WeChat message history on a rooted android phone. +WeChat(微信), as the most popular mobile IM app in China, doesn't give users any method to export well-formatted history message. +This tool can parse and export WeChat messages on a rooted android phone. -It can generate single-file html containing all the messages, including voice message, image, emoji, etc. +It can generate single-file html containing all the messages, including voice messages, images, emoji, etc. __NEWS__: WeChat 6.0+ use silk to encode audio. The code is updated. @@ -17,8 +17,8 @@ __NEWS__: WeChat 6.0+ use silk to encode audio. The code is updated. + [pysox](https://pypi.python.org/pypi/pysox/0.3.6.alpha) + [pysqlcipher](https://pypi.python.org/pypi/pysqlcipher) + numpy -+ python-csscompressor(optional) -+ adb and rooted android phone connected to PC ++ python-csscompressor (suggested, optional) ++ adb and rooted android phone connected to a Linux/Mac OS. + Silk audio decoder (just run `./third-party/compile_silk.sh`) + gnu-sed diff --git a/wechat/parser.py b/wechat/parser.py index a447d7a..d87e562 100644 --- a/wechat/parser.py +++ b/wechat/parser.py @@ -58,10 +58,11 @@ SELECT {} FROM message msg = WeChatMsg(row) if not WeChatMsg.filter_type(msg.type): self.msgs_by_talker[msg.talker].append(msg) - #if msg.type > 10000 or msg.type < 0: - #print repr(msg).split('|')[0] + + # It's possible that messages are kept in database after contacts been deleted + # TODO handle this with a random contact name self.msgs_by_talker = {self.contacts[k]: sorted(v, key=lambda x: x.createTime) - for k, v in self.msgs_by_talker.iteritems()} + for k, v in self.msgs_by_talker.iteritems() if k in self.contacts} for k, v in self.msgs_by_talker.iteritems(): for msg in v: msg.talker_name = ensure_unicode(k)