@@ -322,6 +322,43 @@ def shrink(self, bigurl):
322
322
323
323
tweetburner = Tweetburner ()
324
324
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
+
325
362
"""Mapping of domain to service class"""
326
363
services = {
327
364
'sandbox' : sandbox ,
@@ -331,7 +368,8 @@ def shrink(self, bigurl):
331
368
'bit.ly' : bitly ,
332
369
'is.gd' : isgd ,
333
370
'cli.gs' : cligs ,
334
- 'tweetburner' : tweetburner , 'twurl.nl' : tweetburner
371
+ 'tweetburner' : tweetburner , 'twurl.nl' : tweetburner ,
372
+ 'digg.com' : digg
335
373
}
336
374
337
375
"""
0 commit comments