Created
January 21, 2015 05:28
-
-
Save BlaneyXYZ/e2113b6e98dedee8fa4c to your computer and use it in GitHub Desktop.
YOURLS For CloudBot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@_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