diff options
author | diSabler <dissy@ya.ru> | 2014-01-22 22:01:15 +0400 |
---|---|---|
committer | diSabler <dissy@ya.ru> | 2014-01-22 22:01:15 +0400 |
commit | 5e11b37820ea80e4692530dc10d18a993c756a19 (patch) | |
tree | 9f937a9fd6be5377a717a771a134785b08e284a7 | |
parent | 90cc0319954a36d00b88fbfe7480cc8443255b2c (diff) |
add: most smart trunkate filename while content length was show
-rw-r--r-- | plugins/www.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/plugins/www.py b/plugins/www.py index 490d6fc..16bc96b 100644 --- a/plugins/www.py +++ b/plugins/www.py @@ -22,6 +22,7 @@ # # # --------------------------------------------------------------------------- # +filename_chars_limit = 48 last_url_watch = '' url_watch_ignore = ['pdf','sig','spl','class','ps','torrent','dvi','gz','pac','swf','tar','tgz','tar','zip','mp3','m3u','wma',\ 'wax','ogg','wav','gif','jar','jpg','jpeg','png','xbm','xpm','xwd','css','asc','c','cpp','log','conf','text',\ @@ -206,7 +207,10 @@ def parse_url_in_message(room,jid,nick,type,text): pprint('Show content length: %s in %s' % (link,room),'white') if result: mt = float(body.headers.get('Content-Length',0)) - if mt: send_msg(type, room, '', L('Length of %s is %s','%s/%s'%(jid,nick)) % (u'…/%s' % to_censore(urllib2.unquote(last_url_watch.rsplit('/',1)[-1]).decode('utf-8'),room),get_size_human(mt))) + if mt: + link_end = urllib2.unquote(last_url_watch.rsplit('/',1)[-1]).decode('utf-8') + link_end = u'…%s%s' % (['/',''][len(link_end)>filename_chars_limit], link_end[-filename_chars_limit:]) + send_msg(type, room, '', L('Length of %s is %s','%s/%s'%(jid,nick)) % (to_censore(link_end,room),get_size_human(mt))) except: pass global execute |