Skip to content

Commit 6bb6607

Browse files
committed
Added digg.com service.
1 parent 0f2f6c0 commit 6bb6607

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README

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

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

TODO

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
+ buk.me
33
+ burnurl.com
44
+ chilp.it
5-
+ digg
65
+ fon.gs
76
+ fwd4.me

shorty.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,43 @@ def shrink(self, bigurl):
322322

323323
tweetburner = Tweetburner()
324324

325+
# digg
326+
class Digg(Service):
327+
328+
def __init__(self, appkey=None):
329+
self.appkey = appkey
330+
self.itemid = None
331+
self.view_count = None
332+
333+
def shrink(self, bigurl):
334+
if not self.appkey:
335+
raise ShortyError('Must set an appkey')
336+
resp = request('http://services.digg.com/url/short/create',
337+
{'url': bigurl, 'appkey': self.appkey, 'type': 'json'})
338+
jdata = json.loads(resp.read())['shorturls'][0]
339+
self.itemid = jdata['itemid']
340+
self.view_count = jdata['view_count']
341+
return str(jdata['short_url'])
342+
343+
def expand(self, tinyurl):
344+
if self.appkey:
345+
turl = urlparse(tinyurl)
346+
if turl.netloc != 'digg.com' and turl.netloc != 'www.digg.com':
347+
raise ShortyError('Not a valid digg url')
348+
resp = request('http://services.digg.com/url/short/%s' % quote(
349+
turl.path.strip('/')),
350+
{'appkey': self.appkey, 'type': 'json'})
351+
jdata = json.loads(resp.read())['shorturls'][0]
352+
self.itemid = jdata['itemid']
353+
self.view_count = jdata['view_count']
354+
return str(jdata['link'])
355+
else:
356+
self.itemid = None
357+
self.view_count = None
358+
return get_redirect(tinyurl)
359+
360+
digg = Digg()
361+
325362
"""Mapping of domain to service class"""
326363
services = {
327364
'sandbox': sandbox,
@@ -331,7 +368,8 @@ def shrink(self, bigurl):
331368
'bit.ly': bitly,
332369
'is.gd': isgd,
333370
'cli.gs': cligs,
334-
'tweetburner': tweetburner, 'twurl.nl': tweetburner
371+
'tweetburner': tweetburner, 'twurl.nl': tweetburner,
372+
'digg.com': digg
335373
}
336374

337375
"""

0 commit comments

Comments
 (0)