refactor avatar css
This commit is contained in:
+18
-2
@@ -1,7 +1,10 @@
|
||||
#!/bin/bash -e
|
||||
# File: android-interact.sh
|
||||
# Date: Wed Dec 31 23:27:47 2014 +0800
|
||||
# Date: Wed Dec 31 23:42:08 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
PROG_NAME=`readlink -f "$0"`
|
||||
PROG_DIR=`dirname "$PROG_NAME"`
|
||||
cd "$PROG_DIR"
|
||||
|
||||
# Please check that your path is the same, since this might be different among devices
|
||||
RES_DIR="/mnt/sdcard/tencent/MicroMsg"
|
||||
@@ -63,8 +66,21 @@ elif [[ $1 == "db" || $1 == "res" ]]; then
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
elif [[ $1 == "all" ]]; then
|
||||
echo "Getting uin..."
|
||||
$0 uin | tail -n1 | grep -o '[0-9]*' > /tmp/uin
|
||||
echo "Getting imei..."
|
||||
$0 imei | tail -n1 | grep -o '[0-9]*' > /tmp/imei
|
||||
echo "Getting db..."
|
||||
$0 db
|
||||
echo "Decrypting db..."
|
||||
./decrypt_db.sh EnMicroMsg.db $(</tmp/imei) $(</tmp/uin)
|
||||
rm /tmp/{uin,imei}
|
||||
echo "Getting res..."
|
||||
$0 res
|
||||
echo "Done"
|
||||
else
|
||||
echo "Usage: $0 <imei|uin|db|res>"
|
||||
echo "Usage: $0 <imei|uin|db|res|all>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash -e
|
||||
# File: decrypt_db.sh
|
||||
# Date: Fri Dec 26 00:16:12 2014 +0800
|
||||
# Date: Wed Dec 31 23:38:16 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
MSGDB=$1
|
||||
@@ -33,4 +33,4 @@ SELECT sqlcipher_export("db");
|
||||
DETACH DATABASE db;
|
||||
EOF
|
||||
|
||||
echo "Database dumped to $output"
|
||||
echo "Database successfully dumped to $output"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: parser.py
|
||||
# Date: Thu Dec 25 00:34:35 2014 +0800
|
||||
# Date: Fri Jan 02 23:02:25 2015 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import sqlite3
|
||||
|
||||
+38
-27
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: render.py
|
||||
# Date: Thu Dec 25 22:05:41 2014 +0800
|
||||
# Date: Fri Jan 02 23:23:51 2015 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import os
|
||||
@@ -12,6 +12,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
LIB_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||
HTML_FILE = os.path.join(LIB_PATH, 'static', 'template.html')
|
||||
FRIEND_AVATAR_CSS_FILE = os.path.join(LIB_PATH, 'static', 'avatar.css.tpl')
|
||||
TIME_HTML_FILE = os.path.join(LIB_PATH, 'static', 'TP_TIME.html')
|
||||
|
||||
try:
|
||||
@@ -42,32 +43,35 @@ class HTMLRender(object):
|
||||
logger.warn("Resource Directory not given. Images / Voice Message won't be displayed.")
|
||||
self.smiley = SmileyProvider()
|
||||
|
||||
csss = glob.glob(os.path.join(LIB_PATH, 'static/*.css'))
|
||||
css_string = []
|
||||
for css in csss:
|
||||
css_files = glob.glob(os.path.join(LIB_PATH, 'static/*.css'))
|
||||
self.css_string = [] # css to add
|
||||
for css in css_files:
|
||||
logger.info("Loading {}".format(os.path.basename(css)))
|
||||
css = ensure_unicode(css_compress(open(css).read()))
|
||||
css = u'<style type="text/css">{}</style>'.format(css)
|
||||
css_string.append(css)
|
||||
self.css_string = u"\n".join(css_string)
|
||||
css = ensure_unicode((open(css).read()))
|
||||
self.css_string.append(css)
|
||||
|
||||
jss = glob.glob(os.path.join(LIB_PATH, 'static/*.js'))
|
||||
js_string = []
|
||||
for js in jss:
|
||||
js_files = glob.glob(os.path.join(LIB_PATH, 'static/*.js'))
|
||||
self.js_string = []
|
||||
for js in js_files:
|
||||
logger.info("Loading {}".format(os.path.basename(js)))
|
||||
js = ensure_unicode(open(js).read())
|
||||
# TODO: add js compress
|
||||
js = u'<script type="text/javascript">{}</script>'.format(js)
|
||||
js_string.append(js)
|
||||
self.js_string = u"\n".join(js_string)
|
||||
self.js_string.append(js)
|
||||
|
||||
def get_avatar_pair(self, username):
|
||||
""" return base64 string pair of two avatars"""
|
||||
if self.res is None:
|
||||
return ("", "")
|
||||
avt1 = self.res.get_avatar(self.parser.username)
|
||||
avt2 = self.res.get_avatar(username)
|
||||
return (avt1, avt2)
|
||||
def get_all_css(self):
|
||||
ret = []
|
||||
for css in self.css_string:
|
||||
css = css_compress(css)
|
||||
css = u'<style type="text/css">{}</style>'.format(css)
|
||||
ret.append(css)
|
||||
return u"\n".join(ret)
|
||||
|
||||
def get_all_js(self):
|
||||
ret = []
|
||||
for js in self.js_string:
|
||||
## TODO: add js compress
|
||||
js = u'<script type="text/javascript">{}</script>'.format(js)
|
||||
ret.append(js)
|
||||
return u"\n".join(ret)
|
||||
|
||||
def render_msg(self, msg):
|
||||
""" render a message, return the html block"""
|
||||
@@ -144,16 +148,23 @@ class HTMLRender(object):
|
||||
blocks.extend([self.render_msg(m) for m in slice])
|
||||
self.prgs.trigger(len(slice))
|
||||
|
||||
return self.html.format(extra_css=self.css_string,
|
||||
extra_js=self.js_string,
|
||||
return self.html.format(extra_css=self.get_all_css(),
|
||||
extra_js=self.get_all_js(),
|
||||
talker=msgs[0].talker_name,
|
||||
messages=u''.join(blocks),
|
||||
avatars=self.avatars)
|
||||
messages=u''.join(blocks)
|
||||
)
|
||||
|
||||
def prepare_avatar_css(self, talker_name):
|
||||
avatars = (self.res.get_avatar(self.parser.username),
|
||||
self.res.get_avatar(talker_name))
|
||||
avatar_css = open(FRIEND_AVATAR_CSS_FILE).read().format(avatars=avatars)
|
||||
self.css_string.append(avatar_css)
|
||||
|
||||
def render_msgs(self, msgs):
|
||||
""" render msgs of one friend, return a list of html"""
|
||||
talker_name = msgs[0].talker
|
||||
self.avatars = self.get_avatar_pair(talker_name)
|
||||
self.prepare_avatar_css(talker_name)
|
||||
|
||||
logger.info(u"Rendering {} messages of {}({})".format(
|
||||
len(msgs), self.parser.contacts[talker_name], talker_name))
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: UTF-8 -*-
|
||||
# File: smiley.py
|
||||
# Date: Wed Dec 24 22:16:33 2014 +0800
|
||||
# Date: Wed Dec 31 23:33:07 2014 +0800
|
||||
# Author: Yuxin Wu <[email protected]>
|
||||
|
||||
import os
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
.me .avatar {{
|
||||
background-size: 100%;
|
||||
background-image: url("data:image/jpeg;base64,{avatars[0]}");
|
||||
}}
|
||||
.you .avatar {{
|
||||
background-size: 100%;
|
||||
background-image: url("data:image/jpeg;base64,{avatars[1]}");
|
||||
}}
|
||||
@@ -3,16 +3,6 @@
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<title>Chat with {talker}</title>
|
||||
<style type="text/css">
|
||||
.me .avatar {{
|
||||
background-size: 100%;
|
||||
background-image: url("data:image/jpeg;base64,{avatars[0]}");
|
||||
}}
|
||||
.you .avatar {{
|
||||
background-size: 100%;
|
||||
background-image: url("data:image/jpeg;base64,{avatars[1]}");
|
||||
}}
|
||||
</style>
|
||||
{extra_css}
|
||||
{extra_js}
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user