From ac03ceb3668edfe0926a40f9d2fc88470a439b1d Mon Sep 17 00:00:00 2001 From: neersighted Date: Tue, 6 Mar 2012 23:06:41 -0800 Subject: [PATCH] fixed bug in shorten.py --- plugins/shorten.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/shorten.py b/plugins/shorten.py index 270194b..df977b1 100755 --- a/plugins/shorten.py +++ b/plugins/shorten.py @@ -12,28 +12,30 @@ class ShortenError(Exception): def __str__(self): return repr(self.value) - + def bitly(url, user, apikey): try: + if url[:7] != "http://": + url = "http://" + url params = urlencode({'longUrl': url, 'login': user, 'apiKey': apikey, 'format': 'json'}) j = http.get_json("http://api.bit.ly/v3/shorten?%s" % params) if j['status_code'] == 200: return j['data']['url'] - raise ShortenError('%s'%j['status_txt']) + raise ShortenError('%s' % j['status_txt']) except (HTTPError, ShortenError): return "Could not shorten %s!" % url @hook.command -def shorten(inp, bot=None): +def shorten(inp, bot = None): ".shorten - Makes an j.mp/bit.ly shortlink to the url provided." - api_user = bot.config.get("api_keys", {}).get("bitly_user", None) + api_user = bot.config.get("api_keys", {}).get("bitly_user", None) api_key = bot.config.get("api_keys", {}).get("bitly_api", None) if api_key is None: return "error: no api key set" return bitly(inp, api_user, api_key) @hook.command -def expand(inp, bot=None): +def expand(inp, bot = None): ".expand - Gets the original URL from a shortened link." try: url = http.get_url(inp)