From 10c32e427c23696c8be2f42c500e6f204668ae81 Mon Sep 17 00:00:00 2001 From: Ryan McGrath Date: Thu, 21 May 2009 03:17:47 -0400 Subject: [PATCH] Added a URL shortening method that hits the is.gd API, random comments sprinkled throughout - coming along nicely. Perhaps fallbacks should be provided for when the is.gd API limit is reached? --- tango.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tango.py b/tango.py index a844468..ff1b890 100644 --- a/tango.py +++ b/tango.py @@ -11,6 +11,7 @@ try: except: print "Tango requires the simplejson library to work. http://www.undefined.org/python/" +# Should really deprecate httplib2 at some point... try: import httplib2 except: @@ -41,6 +42,11 @@ class setup: else: pass + def shortenURL(self, url_to_shorten): + # Perhaps we should have fallbacks here in case the is.gd API limit gets hit? Maybe allow them to set the host? + shortURL = urllib2.urlopen("http://is.gd/api.php?" + urllib.urlencode({"longurl": url_to_shorten})).read() + return shortURL + def constructApiURL(self, base_url, params): queryURL = base_url questionMarkUsed = False