diff --git a/dump_msg.py b/dump_msg.py index d0dd45f..4e5c49e 100755 --- a/dump_msg.py +++ b/dump_msg.py @@ -1,10 +1,11 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: dump_msg.py -# Date: Wed Mar 25 17:44:34 2015 +0800 +# Date: Mon May 25 15:16:31 2015 +0800 # Author: Yuxin Wu from wechat.parser import WeChatDBParser +from wechat.utils import safe_filename import sys, os if len(sys.argv) != 3: @@ -23,6 +24,6 @@ parser = WeChatDBParser(db_file) for name, msgs in parser.msgs_by_talker.iteritems(): print u"Writing msgs for {}".format(name) - with open(os.path.join(output_dir, name + '.txt'), 'w') as f: + with open(os.path.join(output_dir, safe_filename(name) + '.txt'), 'w') as f: for m in msgs: print >> f, m diff --git a/wechat/msg.py b/wechat/msg.py index dfbd974..d5f6e69 100644 --- a/wechat/msg.py +++ b/wechat/msg.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: msg.py -# Date: Wed Mar 25 22:27:58 2015 +0800 +# Date: Wed May 06 10:47:57 2015 +0800 # Author: Yuxin Wu TYPE_MSG = 1 TYPE_IMG = 3 @@ -83,7 +83,7 @@ class WeChatMsg(object): name = msg['alias'] if not name: name = "" - return u"NAMECARD: {}".format(name) + return u"NAMECARD: {}".format(self.content_xml_ready) elif self.type == TYPE_APP_MSG: pq = PyQuery(self.content_xml_ready, parser='xml') return pq('title').text() diff --git a/wechat/utils.py b/wechat/utils.py index 491e287..8cf7db9 100644 --- a/wechat/utils.py +++ b/wechat/utils.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: utils.py -# Date: Sun Jan 11 23:38:16 2015 +0800 +# Date: Mon May 25 15:16:14 2015 +0800 # Author: Yuxin Wu import sys @@ -167,3 +167,7 @@ def md5(s): def get_file_b64(fname): data = open(fname, 'rb').read() return base64.b64encode(data) + +def safe_filename(fname): + return "".join( + [c for c in filename if c.isalpha() or c.isdigit() or c==' ']).rstrip()