Skip to content

Commit 4945454

Browse files
committed
Implemented a.gd service. url redirect expand now works with 302.
1 parent 70bd41e commit 4945454

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Supported URL shortening services for shrinking long urls:
1818
cli.gs
1919
twurl.nl (tweetburner)
2020
digg.com
21+
a.gd
2122

2223
Shorty can expand any url service by getting the redirect
2324
location by requesting the tiny url.

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
+ a.gd
21
+ buk.me
32
+ burnurl.com
43
+ chilp.it

shorty.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ def get_redirect(url):
8383
class StopRedirectHandler(HTTPRedirectHandler):
8484
def http_error_301(self, req, fp, code, smg, headers):
8585
return None
86+
def http_error_302(self, req, fp, code, smg, headers):
87+
return None
8688
o = build_opener(StopRedirectHandler())
8789
try:
8890
o.open(url)
8991
except HTTPError, e:
90-
if e.code == 301:
92+
if e.code == 301 or e.code == 302:
9193
return e.headers['Location']
9294
else:
9395
raise ShortyError(e)
@@ -359,6 +361,26 @@ def expand(self, tinyurl):
359361

360362
digg = Digg()
361363

364+
class Agd(Service):
365+
366+
def shrink(self, bigurl, tag=None, password=None, expires=None):
367+
post_param = {'url': bigurl}
368+
if tag:
369+
post_param['tag'] = tag
370+
if password:
371+
post_param['pass'] = password
372+
if expires:
373+
post_param['validTill'] = expires
374+
resp = request('http://a.gd/?module=ShortURL&file=Add&mode=API',
375+
post_data = urlencode(post_param))
376+
url = resp.read()
377+
if url.startswith('http://'):
378+
return url
379+
else:
380+
raise ShortyError(url[url.find('>')+1:url.rfind('<')])
381+
382+
agd = Agd()
383+
362384
"""Mapping of domain to service class"""
363385
services = {
364386
'sandbox': sandbox,
@@ -369,7 +391,8 @@ def expand(self, tinyurl):
369391
'is.gd': isgd,
370392
'cli.gs': cligs,
371393
'tweetburner': tweetburner, 'twurl.nl': tweetburner,
372-
'digg.com': digg
394+
'digg.com': digg,
395+
'a.gd': agd
373396
}
374397

375398
"""

0 commit comments

Comments
 (0)