mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 20:52:42 +01:00
ShrinkUrl: Decode data from web services.
This commit is contained in:
parent
3dc8e04195
commit
5ae3e3fdcf
@ -157,6 +157,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
return self.db.get('ln', url)
|
return self.db.get('ln', url)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
text = utils.web.getUrl('http://ln-s.net/home/api.jsp?url=' + url)
|
text = utils.web.getUrl('http://ln-s.net/home/api.jsp?url=' + url)
|
||||||
|
text = text.decode()
|
||||||
(code, text) = text.split(None, 1)
|
(code, text) = text.split(None, 1)
|
||||||
text = text.strip()
|
text = text.strip()
|
||||||
if code == '200':
|
if code == '200':
|
||||||
@ -185,6 +186,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
return self.db.get('tiny', url)
|
return self.db.get('tiny', url)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
text = utils.web.getUrl('http://tinyurl.com/api-create.php?url=' + url)
|
text = utils.web.getUrl('http://tinyurl.com/api-create.php?url=' + url)
|
||||||
|
text = text.decode()
|
||||||
if text.startswith('Error'):
|
if text.startswith('Error'):
|
||||||
raise ShrinkError, text[5:]
|
raise ShrinkError, text[5:]
|
||||||
self.db.set('tiny', url, text)
|
self.db.set('tiny', url, text)
|
||||||
@ -212,7 +214,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
return self.db.get('xrl', quotedurl)
|
return self.db.get('xrl', quotedurl)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
data = utils.web.urlencode({'long_url': url})
|
data = utils.web.urlencode({'long_url': url})
|
||||||
text = utils.web.getUrl(self._xrlApi, data=data)
|
text = utils.web.getUrl(self._xrlApi, data=data).decode()
|
||||||
if text.startswith('ERROR:'):
|
if text.startswith('ERROR:'):
|
||||||
raise ShrinkError, text[6:]
|
raise ShrinkError, text[6:]
|
||||||
self.db.set('xrl', quotedurl, text)
|
self.db.set('xrl', quotedurl, text)
|
||||||
@ -241,8 +243,8 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
text = utils.web.getUrl(self._gooApi,
|
text = utils.web.getUrl(self._gooApi,
|
||||||
headers={'content-type':'application/json'},
|
headers={'content-type':'application/json'},
|
||||||
data=json.dumps({'longUrl': url}))
|
data=json.dumps({'longUrl': url}).encode())
|
||||||
googl = json.loads(text)['id']
|
googl = json.loads(text.decode())['id']
|
||||||
if len(googl) > 0 :
|
if len(googl) > 0 :
|
||||||
self.db.set('goo', url, googl)
|
self.db.set('goo', url, googl)
|
||||||
return googl
|
return googl
|
||||||
@ -268,7 +270,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
|
|||||||
try:
|
try:
|
||||||
return self.db.get('x0', url)
|
return self.db.get('x0', url)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
text = utils.web.getUrl(self._x0Api % url)
|
text = utils.web.getUrl(self._x0Api % url).decode()
|
||||||
if text.startswith('ERROR:'):
|
if text.startswith('ERROR:'):
|
||||||
raise ShrinkError, text[6:]
|
raise ShrinkError, text[6:]
|
||||||
self.db.set('x0', url, text)
|
self.db.set('x0', url, text)
|
||||||
|
Loading…
Reference in New Issue
Block a user