minor fixes..

This commit is contained in:
ppwwyyxx
2014-12-21 23:54:19 +08:00
parent 4065a9bbac
commit e2d2f5166f
4 changed files with 22 additions and 13 deletions
+14 -6
View File
@@ -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 <[email protected]>
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:<a target="_blank" href="{0}">{0}</a>'.format(url)
return template.format(sender_label=sender,
content=content)
return fallback()
def render_msgs(self, msgs):
+2 -1
View File
@@ -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 <[email protected]>
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)
+3 -3
View File
@@ -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 <[email protected]>
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
+3 -3
View File
@@ -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}}}}
}});
}});
</script>
</body>
</html>