Skip to content

Added qrcode service in bit.ly and goo.gl #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 3, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions services/bitly.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,21 @@ def expand(self, tinyurl):
raise ShortyError(jdata['errorMessage'])
return str(jdata['results'].values()[0]['longUrl'])

def stats(self, tinyurl):
if not self.login:
return get_redirect(tinyurl)
parameters, username_pass = self._setup()
parameters['shortUrl'] = tinyurl
resp = request('http://api.bit.ly/v3/clicks', parameters, username_pass)
jdata = json.loads(resp.read())
if jdata['status_code'] != 200:
raise ShortyError(jdata['errorMessage'])
clicks = {}
clicks['user'] = jdata['data']['clicks'][0]['user_clicks']
clicks['global'] = jdata['data']['clicks'][0]['global_clicks']
return clicks

def qrcode(self, tinyurl):
qrdata = request(tinyurl + '.qrcode').read()
return qrdata

4 changes: 4 additions & 0 deletions services/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ def shrink(self, bigurl):
else:
return jdata['short_url']

def qrcode(self, tinyurl):
qrdata = request(tinyurl + '.qr').read()
return qrdata