Skip to content

Instantly share code, notes, and snippets.

@BlaneyXYZ
Created January 21, 2015 05:28
Show Gist options
  • Save BlaneyXYZ/e2113b6e98dedee8fa4c to your computer and use it in GitHub Desktop.
Save BlaneyXYZ/e2113b6e98dedee8fa4c to your computer and use it in GitHub Desktop.
YOURLS For CloudBot
@_shortener('blny.tk')
class Blnytk(Shortener):
def shorten(self, url, custom=None):
p = {'signature': '', 'format': 'json', 'keyword': custom, 'action': 'shorturl', 'url': url}
h = {'User-Agent': 'CloudBot Refresh'}
r = requests.get('http://blny.me/api.php', params=p, headers=h)
j = r.json()
if 'shorturl' in j:
return j['shorturl']
else:
raise ServiceError(j['message'], r)
def expand(self, url):
p = {'signature': '', 'action': 'expand', 'shorturl': url, 'format': 'json'}
h = {'User-Agent': 'CloudBot Refresh'}
r = requests.get('http://blny.me/api.php', params=p, headers=h)
j = r.json()
if 'longurl' in j:
return j['longurl']
else:
raise ServiceError(j['message'], r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment