From a27f51c84bf15142e096cbf5fc0e8c468f7f5f3b Mon Sep 17 00:00:00 2001 From: The Dod Date: Tue, 13 May 2014 22:11:09 +0300 Subject: [PATCH] Prepend "protocol less" urls with http:// (fix #6) Also remove an embarrassing debug print :s --- swizzler.py | 1 - twister.py | 9 ++++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/swizzler.py b/swizzler.py index 4629c75..63e4a4f 100644 --- a/swizzler.py +++ b/swizzler.py @@ -209,7 +209,6 @@ if __name__ == '__main__': cherrypy.tree.mount(app,'/',config='{0}/cherrypy.config'.format(APPDIR)) conf = cherrypy.tree.apps[''].config u,p = conf['swizzler'].get('browser_user'),conf['swizzler'].get('browser_password') - print u,p if u and p: conf['/'].update({ 'tools.basic_auth.on': True, 'tools.basic_auth.realm': 'Swizzler VIP lounge', diff --git a/twister.py b/twister.py index 82eb71b..28803dd 100644 --- a/twister.py +++ b/twister.py @@ -1,6 +1,9 @@ import time from bitcoinrpc.authproxy import AuthServiceProxy from functioncache import functioncache,SkipCache +import re + +RE_URL_TWEAK = re.compile('^https?://',re.I) def timestamp2iso(t): return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(t)) @@ -75,7 +78,11 @@ class Twister: user['username'] = username # handy if not user.get('fullname'): # happens user['fullname'] = username.capitalize() # Buddha is in the details - user['bio']=self._format_message(user.get('bio','')) + user['bio'] = self._format_message(user.get('bio','')) + # Tweak for "protcol-less" urls + u = user.get('url') + if u and not RE_URL_TWEAK.match(u): + user['url'] = 'http://{0}'.format(u) try: user['avatar'] = self.twister.dhtget(username,'avatar','s')[0]['p']['v'] if user['avatar']=='img/genericPerson.png': # ugly patch