From 7d463de45eb68b178fa8f622cf30b75957057408 Mon Sep 17 00:00:00 2001 From: ppwwyyxx Date: Sun, 21 Dec 2014 23:54:19 +0800 Subject: [PATCH] minor fixes.. --- README.md | 2 ++ lib/render.py | 20 ++++++++++++++------ lib/res.py | 3 ++- lib/smiley.py | 6 +++--- lib/static/template.html | 6 +++--- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c628c14..1182333 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ ### TODO + Parse uncommon message types + Add date/time in html ++ Show href for LINK type ++ Internal emoji parsing. 'EmojiInfo' table. + Fix smiley spacing in html + Show name of emoji in text output + Search by uid/username.. diff --git a/lib/render.py b/lib/render.py index b40f48f..37adfd6 100644 --- a/lib/render.py +++ b/lib/render.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: render.py -# Date: Sun Dec 21 21:21:53 2014 +0800 +# Date: Sun Dec 21 23:48:29 2014 +0800 # Author: Yuxin Wu import os @@ -25,9 +25,10 @@ from smiley import SmileyProvider TEMPLATES_FILES = {TYPE_MSG: "TP_MSG", TYPE_IMG: "TP_IMG", TYPE_SPEAK: "TP_SPEAK", - TYPE_EMOJI: "TP_EMOJI"} -TEMPLATES = dict([(k, open(os.path.join( - LIB_PATH, 'static/{}.html'.format(v))).read()) + TYPE_EMOJI: "TP_EMOJI", + TYPE_LINK: "TP_MSG"} +TEMPLATES = dict([(k, ensure_unicode(open(os.path.join( + LIB_PATH, 'static/{}.html'.format(v))).read())) for k, v in TEMPLATES_FILES.iteritems()]) class HTMLRender(object): @@ -70,7 +71,7 @@ class HTMLRender(object): """ render a message, return the html block""" sender = 'you' if not msg.isSend else 'me' def fallback(): - template = ensure_unicode(TEMPLATES[1]) + template = TEMPLATES[TYPE_MSG] content = msg.msg_str() content = self.smiley.replace_smileycode(content) return template.format(sender_label=sender, @@ -78,7 +79,7 @@ class HTMLRender(object): if msg.type not in TEMPLATES: return fallback() - template = ensure_unicode(TEMPLATES[msg.type]) + template = TEMPLATES[msg.type] if msg.type == TYPE_SPEAK: audio_str, duration = self.res.get_voice_mp3(msg.imgPath) return template.format(sender_label=sender, @@ -108,6 +109,13 @@ class HTMLRender(object): return template.format(sender_label=sender, emoji_format=format, emoji_img=emoji_img) + elif msg.type == TYPE_LINK: + content = msg.msg_str() + if content.startswith(u'URL:'): + url = content[4:] + content = u'URL:{0}'.format(url) + return template.format(sender_label=sender, + content=content) return fallback() def render_msgs(self, msgs): diff --git a/lib/res.py b/lib/res.py index 6306a27..02a509d 100644 --- a/lib/res.py +++ b/lib/res.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: res.py -# Date: Sun Dec 21 21:22:44 2014 +0800 +# Date: Sun Dec 21 23:49:46 2014 +0800 # Author: Yuxin Wu import glob @@ -157,6 +157,7 @@ class Resource(object): 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 assert len(candidates) == 1 + print candidates, md5 fname = candidates[0] return Resource.get_file_b64(fname), imghdr.what(fname) diff --git a/lib/smiley.py b/lib/smiley.py index 7b6abe6..ae84f98 100755 --- a/lib/smiley.py +++ b/lib/smiley.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # -*- coding: UTF-8 -*- # File: smiley.py -# Date: Sat Dec 20 17:49:42 2014 +0800 +# Date: Sun Dec 21 23:41:14 2014 +0800 # Author: Yuxin Wu import os @@ -58,7 +58,7 @@ class SmileyProvider(object): def _replace_tencent(self, msg): if (not '[' in msg or not ']' in msg) \ - and (not '\:' in msg) and (not '/' in msg): + and (not '/:' in msg) and (not '/' in msg): return msg for k, v in self.tencent_smiley.iteritems(): if k in msg: @@ -76,6 +76,6 @@ class SmileyProvider(object): if __name__ == '__main__': smiley = SmileyProvider() - msg = u"[挥手]哈哈呵呵hihi\U0001f684\u2728\u0001" + msg = u"[挥手]哈哈呵呵hihi\U0001f684\u2728\u0001 /::<" msg = smiley.replace_smileycode(msg) print msg diff --git a/lib/static/template.html b/lib/static/template.html index 36725e0..9118bad 100644 --- a/lib/static/template.html +++ b/lib/static/template.html @@ -46,9 +46,9 @@ var playVoice = function(event) {{ $(document).ready(function() {{ $(".fancybox").fancybox({{ // fancybox will otherwise scroll page to top -helpers: {{ overlay : {{ locked : false}}}} -}}); - }}); + helpers: {{ overlay : {{ locked : false}}}} + }}); + }});