Skip to content

Commit 7c6c9a5

Browse files
committed
Added tweetburner service. Implemented shrink and expand.
1 parent 1e41c00 commit 7c6c9a5

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Supported URL shortening services:
1616
bit.ly
1717
is.gd
1818
cli.gs
19+
twurl.nl (tweetburner)
1920

2021
Language: Python
2122
Website: http://gitorious.org/shorty

shorty.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __str__(self):
5656
return repr(self.reason)
5757

5858
"""Do a http request"""
59-
def request(url, parameters=None, username_pass=None):
59+
def request(url, parameters=None, username_pass=None, post_data=None):
6060

6161
# build url + parameters
6262
if parameters:
@@ -72,6 +72,8 @@ def request(url, parameters=None, username_pass=None):
7272
# send request
7373
try:
7474
req = Request(url_params, headers=headers)
75+
if post_data:
76+
req.add_data(post_data)
7577
return urlopen(req)
7678
except URLError, e:
7779
raise ShortyError(e)
@@ -96,13 +98,13 @@ def http_error_301(self, req, fp, code, smg, headers):
9698
"""Base interface that all services implement."""
9799
class Service(object):
98100

99-
def shrink(bigurl):
101+
def shrink(self, bigurl):
100102
"""Take a big url and make it smaller"""
101103

102104
return None
103105

104-
def expand(tinyurl):
105-
return None
106+
def expand(self, tinyurl):
107+
return get_redirect(tinyurl)
106108

107109
""" Services """
108110

@@ -147,9 +149,6 @@ def shrink(self, bigurl):
147149
resp = request('http://tinyurl.com/api-create.php', {'url': bigurl})
148150
return resp.read()
149151

150-
def expand(self, tinyurl):
151-
return get_redirect(tinyurl)
152-
153152
tinyurl = Tinyurl()
154153

155154
# tr.im
@@ -286,9 +285,6 @@ def shrink(self, bigurl):
286285
raise ShortyError(turl)
287286
return turl
288287

289-
def expand(self, tinyurl):
290-
return get_redirect(tinyurl)
291-
292288
isgd = Isgd()
293289

294290
# cli.gs
@@ -317,6 +313,15 @@ def expand(self, tinyurl):
317313

318314
cligs = Cligs()
319315

316+
# tweetburner.com
317+
class Tweetburner(Service):
318+
319+
def shrink(self, bigurl):
320+
resp = request('http://tweetburner.com/links', post_data='link[url]=%s' % bigurl)
321+
return resp.read()
322+
323+
tweetburner = Tweetburner()
324+
320325
"""Mapping of domain to service class"""
321326
services = {
322327
'sandbox': sandbox,
@@ -325,7 +330,8 @@ def expand(self, tinyurl):
325330
'urlborg.com': urlborg, 'ub0.cc': urlborg,
326331
'bit.ly': bitly,
327332
'is.gd': isgd,
328-
'cli.gs': cligs
333+
'cli.gs': cligs,
334+
'tweetburner': tweetburner, 'twurl.nl': tweetburner
329335
}
330336

331337
"""

0 commit comments

Comments
 (0)