fix 1048625

This commit is contained in:
ppwwyyxx
2015-01-07 23:46:08 +08:00
parent 29cb4037e2
commit 1a655c37e7
6 changed files with 30 additions and 22 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash -e
# File: decrypt_db.sh
# Date: Wed Jan 07 22:08:56 2015 +0800
# Date: Wed Jan 07 22:34:45 2015 +0800
# Author: Yuxin Wu <[email protected]>
MSGDB=$1
+3 -2
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: msg.py
# Date: Wed Jan 07 22:00:37 2015 +0800
# Date: Wed Jan 07 23:30:41 2015 +0800
# Author: Yuxin Wu <[email protected]>
import re
@@ -21,13 +21,14 @@ TYPE_LINK = 49 # link share OR file from web
TYPE_VOIP = 50
TYPE_WX_VIDEO = 62 # video took by wechat
TYPE_SYSTEM = 10000
TYPE_CUSTOM_EMOJI = 1048625
class WeChatMsg(object):
FIELDS = ["msgSvrId","type","isSend","createTime","talker","content","imgPath"]
@staticmethod
def filter_type(tp):
if tp in [TYPE_SYSTEM] or tp > 10000 or tp < 0:
if tp in [TYPE_SYSTEM]:
return True
return False
+3 -1
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: parser.py
# Date: Fri Jan 02 23:02:25 2015 +0800
# Date: Wed Jan 07 23:29:50 2015 +0800
# Author: Yuxin Wu <[email protected]>
import sqlite3
@@ -58,6 +58,8 @@ 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]
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():
+18 -12
View File
@@ -1,13 +1,14 @@
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: render.py
# Date: Wed Jan 07 22:03:53 2015 +0800
# Date: Wed Jan 07 23:43:59 2015 +0800
# Author: Yuxin Wu <[email protected]>
import os
import base64
import glob
import logging
from pyquery import PyQuery
logger = logging.getLogger(__name__)
LIB_PATH = os.path.dirname(os.path.abspath(__file__))
@@ -30,6 +31,7 @@ TEMPLATES_FILES = {TYPE_MSG: "TP_MSG",
TYPE_IMG: "TP_IMG",
TYPE_SPEAK: "TP_SPEAK",
TYPE_EMOJI: "TP_EMOJI",
TYPE_CUSTOM_EMOJI: "TP_IMG",
TYPE_LINK: "TP_MSG"}
TEMPLATES = {k: ensure_unicode(open(os.path.join(STATIC_PATH, '{}.html'.format(v))).read())
for k, v in TEMPLATES_FILES.iteritems()}
@@ -72,6 +74,7 @@ class HTMLRender(object):
def render_msg(self, msg):
""" render a message, return the html block"""
# TODO for chatroom, add nickname on avatar
sender = u'you ' + msg.get_msg_talker_id() if not msg.isSend else 'me'
format_dict = {'sender_label': sender,
'time': msg.createTime }
@@ -81,10 +84,7 @@ class HTMLRender(object):
format_dict['content'] = self.smiley.replace_smileycode(content)
return template.format(**format_dict)
if msg.type not in TEMPLATES:
return fallback()
template = TEMPLATES[msg.type]
template = TEMPLATES.get(msg.type)
if msg.type == TYPE_SPEAK:
audio_str, duration = self.res.get_voice_mp3(msg.imgPath)
format_dict['voice_duration'] = duration
@@ -104,21 +104,27 @@ class HTMLRender(object):
return fallback()
# TODO do not show fancybox when no bigimg found
format_dict['small_img'] = smallimg
format_dict['big_img'] = bigimg
format_dict['big_img'] = (bigimg, 'jpeg')
return template.format(**format_dict)
elif msg.type == TYPE_EMOJI:
imgpath = msg.imgPath
if imgpath in self.parser.internal_emojis:
emoji_img, format = self.res.get_internal_emoji(self.parser.internal_emojis[imgpath])
md5 = msg.imgPath
if md5 in self.parser.internal_emojis:
emoji_img, format = self.res.get_internal_emoji(self.parser.internal_emojis[md5])
else:
if imgpath in self.parser.emojis:
group, _ = self.parser.emojis[imgpath]
if md5 in self.parser.emojis:
group, _ = self.parser.emojis[md5]
else:
group = None
emoji_img, format = self.res.get_emoji(imgpath, group)
emoji_img, format = self.res.get_emoji(md5, group)
format_dict['emoji_format'] = format
format_dict['emoji_img'] = emoji_img
return template.format(**format_dict)
elif msg.type == TYPE_CUSTOM_EMOJI:
pq = PyQuery(msg.content)
md5 = pq('emoticonmd5').text()
format_dict['big_img'] = self.res.get_emoji(md5, None)
format_dict['small_img'] = format_dict['big_img'][0]
return template.format(**format_dict)
elif msg.type == TYPE_LINK:
content = msg.msg_str()
# TODO show a short link with long href, if link too long
+4 -5
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: res.py
# Date: Wed Jan 07 21:21:39 2015 +0800
# Date: Wed Jan 07 22:30:40 2015 +0800
# Author: Yuxin Wu <[email protected]>
import glob
@@ -34,8 +34,6 @@ class Resource(object):
self.res_dir = res_dir
self.img_dir = os.path.join(res_dir, IMG_DIRNAME)
self.emoji_dir = os.path.join(res_dir, EMOJI_DIRNAME)
assert os.path.isdir(self.img_dir), \
"No such directory: {}".format(self.img_dir)
self.avt_reader = AvatarReader(self.res_dir)
self.init()
@@ -52,7 +50,7 @@ class Resource(object):
full_path = os.path.join(root, f)
key = f[4:-4] # msg_xxxxx.amr
assert len(key) == 26, \
"Error interpreting the protocol, this is a bug!"
"Error interpreting the protocol, this is potentially a bug!"
self.speak_data[key] = full_path
def get_voice_mp3(self, imgpath):
@@ -163,9 +161,10 @@ class Resource(object):
if len(candidates) > 1:
# annimation
candidates = [k for k in candidates if not re.match('.*_[0-9]+$', k)]
# only one file is the gif in need, others are frames and cover
# only one file is the gif in need, others are frames or cover
if len(candidates) == 0:
# TODO stitch frames to gif
logger.warning("Cannot find emoji: {}".format(md5))
return None, None
if not candidates:
return None, None
+1 -1
View File
@@ -6,7 +6,7 @@
<div class="cloudBody">
<div class="cloudContent">
<span class="img_wrap">
<a class="fancybox" rel="group" href="data:image/jpeg;base64,{big_img}">
<a class="fancybox" rel="group" href="data:image/{big_img[1]};base64,{big_img[0]}">
<img class="zoomIn imageBorder" src="data:image/jpeg;base64,{small_img}"/>
</a>
</span>