1. Mike Griffith
  2. zine-main

Commits

Mike Griffith  committed c9db81b

support tinyurl as well

  • Participants
  • Parent commits 21298ff
  • Branches default

Comments (0)

Files changed (1)

File zine/plugins/twitter/__init__.py

View file
     from twitter import Api as twitter_api
 except ImportError:
     twitter_api = None
-try:
-    from bitly import Api as bitly_api
-except ImportError:
-    bitly_api = None
 
 
 SHARED = join(dirname(__file__), 'shared')
 MESSAGE = 'BLOGGED: {title} {url} #zine'
 
 
+URL_SHORTENERS = (
+        'bit.ly',
+        'tinyurl',
+        )
+
+
 def setup(app, plugin):
     app.add_config_var('twitter/username',
                        forms.TextField(default=u''))
     url = url_for(post)
 
     url_shortener = config['twitter/url_shortener']
-    if url_shortener == "b":
-        if bitly_api is None:
-            raise ValueError("python-bitly API is not available.  Please check site-packages.")
+    if url_shortener == "bit.ly":
+        from bitly import Api as bitly_api
         login = config['twitter/bitly_login']
         apikey = config['twitter/bitly_apikey']
         url = bitly_api(login=login, apikey=apikey).shorten(url)
+    elif url_shortener == "tinyurl":
+        import tinyurl
+        url = tinyurl.create_one(url)
 
     return url
 
     bitly_apikey = forms.TextField()
 
     def __init__(self, initial=None):
-        self.url_shortener.choices = [
-                ("", "None"),
-                ("b", "bit.ly")]
+        self.url_shortener.choices = [("", "None")]
+        for url_shortener in URL_SHORTENERS:
+            self.url_shortener.choices.append((url_shortener, url_shortener))
         forms.Form.__init__(self, initial)