generate msg-only html
This commit is contained in:
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: dump_html.py
|
||||
# Date: Sat Nov 22 23:51:45 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import sys
|
||||
if len(sys.argv) != 3:
|
||||
sys.exit("Usage: {0} <path to decoded_database.db> <name>".format(sys.argv[0]))
|
||||
|
||||
from lib.utils import ensure_unicode
|
||||
from lib.parser import WeChatDBParser
|
||||
from lib.render import HTMLRender
|
||||
|
||||
db_file = sys.argv[1]
|
||||
name = ensure_unicode(sys.argv[2])
|
||||
|
||||
parser = WeChatDBParser(db_file)
|
||||
parser.parse()
|
||||
msgs = parser.msgs_by_talker[name]
|
||||
|
||||
render = HTMLRender()
|
||||
html = render.render_msgs(msgs).encode('utf-8')
|
||||
print html
|
||||
+5
-3
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: Msg.py
|
||||
# Date: Sat Nov 22 22:28:15 2014 +0800
|
||||
# File: msg.py
|
||||
# Date: Sat Nov 22 23:23:52 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
from datetime import datetime
|
||||
@@ -35,6 +35,7 @@ class WeChatMsg(object):
|
||||
for f, v in zip(WeChatMsg.FIELDS, row):
|
||||
setattr(self, f, v)
|
||||
self.createTime = datetime.fromtimestamp(self.createTime / 1000)
|
||||
self.talker_name = None
|
||||
if self.content:
|
||||
self.content = ensure_unicode(self.content)
|
||||
|
||||
@@ -70,7 +71,8 @@ class WeChatMsg(object):
|
||||
def __repr__(self):
|
||||
ret = u"{}|{}:{}:{}".format(
|
||||
self.type,
|
||||
ensure_unicode(self.talker) if not self.isSend else 'me',
|
||||
(self.talker if not self.talker_name else self.talker_name) \
|
||||
if not self.isSend else 'me',
|
||||
self.createTime,
|
||||
ensure_unicode(self.msg_str())).encode('utf-8')
|
||||
if self.imgPath:
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: parser.py
|
||||
# Date: Sat Nov 22 22:32:05 2014 +0800
|
||||
# Date: Sat Nov 22 23:23:44 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import sqlite3
|
||||
@@ -56,7 +56,7 @@ SELECT {} FROM message
|
||||
for k, v in self.msgs_by_talker.iteritems()])
|
||||
for k, v in self.msgs_by_talker.iteritems():
|
||||
for msg in v:
|
||||
msg.talker = k
|
||||
msg.talker_name = ensure_unicode(k)
|
||||
|
||||
def _find_msg_by_type(self, msgs=None):
|
||||
ret = []
|
||||
|
||||
+32
-6
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: Render.py
|
||||
# Date: Sat Nov 22 22:29:56 2014 +0800
|
||||
# File: render.py
|
||||
# Date: Sat Nov 22 23:24:10 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import os
|
||||
@@ -9,16 +9,42 @@ LIB_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
CSS_FILE = os.path.join(LIB_PATH, 'static/wx.css')
|
||||
HTML_FILE = os.path.join(LIB_PATH, 'static/template.html')
|
||||
|
||||
try:
|
||||
from csscompressor import compress as css_compress
|
||||
except:
|
||||
css_compress = lambda x: x
|
||||
|
||||
from .msg import *
|
||||
from .utils import ensure_unicode
|
||||
|
||||
TEMPLATES_FILES = {TYPE_MSG: "TP_MSG"}
|
||||
TEMPLATES = dict([(k, open(os.path.join(
|
||||
LIB_PATH, 'static/{}.html'.format(v))).read())
|
||||
for k, v in TEMPLATES_FILES.iteritems()])
|
||||
|
||||
|
||||
|
||||
class HTMLRender(object):
|
||||
def __init__(self, res=None):
|
||||
self.css = open(CSS_FILE).read().replace('\n', '')
|
||||
self.html = open(HTML_FILE).read()
|
||||
self.css = ensure_unicode(css_compress(open(CSS_FILE).read()))
|
||||
self.html = ensure_unicode(open(HTML_FILE).read())
|
||||
self.res = res
|
||||
|
||||
def render_msg(self, msg):
|
||||
""" render a message"""
|
||||
""" render a message, return the block"""
|
||||
# TODO
|
||||
pass
|
||||
#template = ensure_unicode(TEMPLATES[msg.type])
|
||||
template = ensure_unicode(TEMPLATES[1])
|
||||
if False:
|
||||
return ""
|
||||
else:
|
||||
return template.format(sender_label='you' if not msg.isSend else 'me',
|
||||
content=msg.msg_str())
|
||||
|
||||
def render_msgs(self, msgs):
|
||||
blocks = [self.render_msg(m) for m in msgs]
|
||||
return self.html.format(style=self.css, talker=msgs[0].talker_name,
|
||||
messages=u''.join(blocks))
|
||||
|
||||
if __name__ == '__main__':
|
||||
r = HTMLRender()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<div class="chatItem {sender_label}">
|
||||
<div class="chatItemContent">
|
||||
<img class="avatar" src="">
|
||||
<div class="cloud cloudText">
|
||||
<div class="cloudPannel">
|
||||
<div class="cloudBody">
|
||||
<div class="cloudContent">
|
||||
<pre style="white-space:pre-wrap">{content}</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
+24
-24
@@ -1,30 +1,30 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>WeChat</title>
|
||||
<link rel="stylesheet" type="text/css" href="http://localhost:8000/wx.css">
|
||||
<style type="text/css">{style}</style>
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>WeChat</title>
|
||||
<link rel="stylesheet" type="text/css" href="http://localhost:8000/wx.css">
|
||||
<style type="text/css">{style}</style>
|
||||
</head>
|
||||
|
||||
<body ctrl="1">
|
||||
<div id="container">
|
||||
<div id="chat" class="chatPanel normalPanel" ctrl="1">
|
||||
<div class="chatContainer" style="height: 800px;">
|
||||
<div class="chatMainPanel" id="chatMainPanel">
|
||||
<div class="chatTitle">
|
||||
<div class="chatNameWrap">
|
||||
<p class="chatName" id="messagePanelTitle">{talker}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chatScorll" style="height: 770px; overflow-y: scroll; position: relative;">
|
||||
<div id="chat_chatmsglist" class="chatContent" ctrl="1" style="position: absolute;">
|
||||
{messages}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<body>
|
||||
<div id="container">
|
||||
<div id="chat" class="chatPanel normalPanel">
|
||||
<div class="chatContainer" style="height: 800px;">
|
||||
<div class="chatMainPanel" id="chatMainPanel">
|
||||
<div class="chatTitle">
|
||||
<div class="chatNameWrap">
|
||||
<p class="chatName" id="messagePanelTitle">{talker}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chatScorll" style="height: 770px; overflow-y: scroll; position: relative; font-family:initial;">
|
||||
<div id="chat_chatmsglist" class="chatContent" style="position: absolute;">
|
||||
{messages}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+4
-4
@@ -166,9 +166,9 @@ html,
|
||||
body {
|
||||
height: 100%;
|
||||
min-height: 755px;
|
||||
background: #4e5359 url(../images/bg_universal1844c2.png) repeat 0 0;
|
||||
background: #4e5359 repeat 0 0;
|
||||
color: #666;
|
||||
font: 14px/1.5 Helvetica, "微软雅黑", "黑体", Arial, Tahoma;
|
||||
font: 14px/1.5 Helvetica, Arial, Tahoma;
|
||||
text-align: center;
|
||||
overflow-y: auto;
|
||||
}
|
||||
@@ -2435,7 +2435,7 @@ ul.faceTab a.chooseFaceTab {
|
||||
border: none;
|
||||
border-bottom: 1px solid #fff;
|
||||
border: 1px solid #ccc\9;
|
||||
font: 14px/1.5 Helvetica, "微软雅黑", "黑体", Arial, Tahoma;
|
||||
font: 14px/1.5 Helvetica, Arial, Tahoma;
|
||||
line-height: 1.2em;
|
||||
resize: none;
|
||||
}
|
||||
@@ -5266,7 +5266,7 @@ a.btnBlue:active .btnBluePanel {
|
||||
word-wrap: break-word;
|
||||
resize: none;
|
||||
overflow: auto;
|
||||
font: 14px/1.5 Helvetica, "微软雅黑", "黑体", Arial, Tahoma;
|
||||
font: 14px/1.5 Helvetica, Arial, Tahoma;
|
||||
line-height: 1.2em;
|
||||
}
|
||||
.feedbackWin .opArea {
|
||||
|
||||
Reference in New Issue
Block a user