Skip to content

Commit 2aa187e

Browse files
committed
Added stats for bit.ly
1 parent 2b6507e commit 2aa187e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

services/bitly.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,17 @@ def expand(self, tinyurl):
5959
raise ShortyError(jdata['errorMessage'])
6060
return str(jdata['results'].values()[0]['longUrl'])
6161

62+
def stats(self, tinyurl):
63+
if not self.login:
64+
return get_redirect(tinyurl)
65+
parameters, username_pass = self._setup()
66+
parameters['shortUrl'] = tinyurl
67+
resp = request('http://api.bit.ly/v3/clicks', parameters, username_pass)
68+
jdata = json.loads(resp.read())
69+
if jdata['status_code'] != 200:
70+
raise ShortyError(jdata['errorMessage'])
71+
return str(jdata['data']['clicks'][0]['global_clicks'])
72+
6273
def qrcode(self, tinyurl):
6374
qrdata = request(tinyurl + '.qrcode').read()
6475
return qrdata

0 commit comments

Comments
 (0)