various bug fixes
This commit is contained in:
+11
-2
@@ -1,11 +1,13 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: msg.py
|
||||
# Date: Wed Dec 24 22:00:42 2014 +0800
|
||||
# Date: Thu Dec 25 09:56:24 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import re
|
||||
from datetime import datetime
|
||||
from pyquery import PyQuery
|
||||
|
||||
from .utils import ensure_bin_str, ensure_unicode
|
||||
|
||||
TYPE_MSG = 1
|
||||
@@ -66,7 +68,14 @@ class WeChatMsg(object):
|
||||
elif self.type == TYPE_VIDEO:
|
||||
return "VIDEO FILE"
|
||||
elif self.type == TYPE_NAMECARD:
|
||||
pq = PyQuery(self.content)
|
||||
try:
|
||||
pq = PyQuery(self.content)
|
||||
except ValueError:
|
||||
# pq doesn't support xml
|
||||
pat = re.compile('<msg.*<\/msg>', re.DOTALL)
|
||||
msg = pat.search(self.content).group()
|
||||
pq = PyQuery(msg)
|
||||
|
||||
msg = pq('msg').attr
|
||||
name = msg['nickname']
|
||||
if not name:
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: parser.py
|
||||
# Date: Mon Dec 22 22:14:18 2014 +0800
|
||||
# Date: Thu Dec 25 00:34:35 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import sqlite3
|
||||
@@ -32,7 +32,7 @@ class WeChatDBParser(object):
|
||||
self.msgs_by_talker = defaultdict(list)
|
||||
self.emojis = {}
|
||||
self.internal_emojis = {}
|
||||
self.parse()
|
||||
self._parse()
|
||||
|
||||
def _parse_contact(self):
|
||||
contacts = self.cc.execute(
|
||||
@@ -105,7 +105,7 @@ SELECT {} FROM message
|
||||
self.internal_emojis[md5] = name
|
||||
|
||||
|
||||
def parse(self):
|
||||
def _parse(self):
|
||||
self._parse_userinfo()
|
||||
self._parse_contact()
|
||||
self._parse_msg()
|
||||
|
||||
+6
-2
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: render.py
|
||||
# Date: Tue Dec 23 00:01:11 2014 +0800
|
||||
# Date: Thu Dec 25 10:01:58 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import os
|
||||
@@ -92,8 +92,12 @@ class HTMLRender(object):
|
||||
elif msg.type == TYPE_IMG:
|
||||
# imgPath was original THUMBNAIL_DIRPATH://th_xxxxxxxxx
|
||||
imgpath = msg.imgPath.split('_')[-1]
|
||||
if not imgpath:
|
||||
logger.warn('No imgpath in an image message. Perhaps a bug in wechat.')
|
||||
return fallback()
|
||||
bigimgpath = self.parser.imginfo.get(msg.msgSvrId)
|
||||
fnames = [k for k in [imgpath, bigimgpath] if k is not None]
|
||||
fnames = [k for k in [imgpath, bigimgpath] if k]
|
||||
assert len(fnames) > 0, msg.msg_str()
|
||||
bigimg, smallimg = self.res.get_img(fnames)
|
||||
if not smallimg:
|
||||
logger.warn("No image thumbnail found for {}".format(imgpath))
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: res.py
|
||||
# Date: Mon Dec 22 16:52:56 2014 +0800
|
||||
# Date: Thu Dec 25 10:04:29 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import glob
|
||||
@@ -127,6 +127,7 @@ class Resource(object):
|
||||
|
||||
def get_img(self, fnames):
|
||||
""" return two base64 jpg string"""
|
||||
fnames = [k for k in fnames if k] # filter out empty string
|
||||
big_file, small_file = self._get_img_file(fnames)
|
||||
|
||||
def get_jpg_b64(img_file):
|
||||
|
||||
Reference in New Issue
Block a user