mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-26 04:51:09 -05:00
fix link shortening
This commit is contained in:
parent
2756c31bb5
commit
9b7d3f9b4f
33
plugin.py
33
plugin.py
@ -114,14 +114,17 @@ class Tweety(callbacks.Plugin):
|
|||||||
|
|
||||||
api_key = self.registryValue('bitlyKey')
|
api_key = self.registryValue('bitlyKey')
|
||||||
url_enc = urllib.parse.quote_plus(url)
|
url_enc = urllib.parse.quote_plus(url)
|
||||||
api_url = 'https://api-ssl.bitly.com/v3/shorten?access_token={}&longUrl={}&format=txt'
|
api_url = 'https://api-ssl.bitly.com/v3/shorten?access_token={}&longUrl={}&format=json'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url2 = requests.get(api_url.format(api_key, url_enc))
|
data = requests.get(api_url.format(api_key, url_enc)).json()
|
||||||
if 'RATE_LIMIT_EXCEEDED' in url2.text.strip():
|
url2 = data['data'].get('url')
|
||||||
|
if url2.strip():
|
||||||
|
return url2.strip()
|
||||||
|
else:
|
||||||
return url
|
return url
|
||||||
return url2.text.strip()
|
|
||||||
except:
|
except:
|
||||||
|
self.log.error("ERROR: Failed shortening url: {0}".format(longurl))
|
||||||
return url
|
return url
|
||||||
|
|
||||||
def _checkAuthorization(self):
|
def _checkAuthorization(self):
|
||||||
@ -267,16 +270,20 @@ class Tweety(callbacks.Plugin):
|
|||||||
def _createShortUrl(self, nick, tweetid):
|
def _createShortUrl(self, nick, tweetid):
|
||||||
"""Shortens a tweet into a short one."""
|
"""Shortens a tweet into a short one."""
|
||||||
|
|
||||||
|
api_key = self.registryValue('bitlyKey')
|
||||||
|
longurl = "https://twitter.com/%s/status/%s" % (nick, tweetid)
|
||||||
|
api_url = 'https://api-ssl.bitly.com/v3/shorten?access_token={}&longUrl={}&format=json'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
longurl = "https://twitter.com/#!/%s/status/%s" % (nick, tweetid)
|
data = requests.get(api_url.format(api_key, longurl)).json()
|
||||||
posturi = "https://www.googleapis.com/urlshortener/v1/url"
|
url2 = data['data'].get('url')
|
||||||
data = json.dumps({'longUrl': longurl})
|
if url2.strip():
|
||||||
headers = {'Content-Type':'application/json'}
|
return url2.strip()
|
||||||
request = utils.web.getUrl(posturi, data=data, headers=headers)
|
else:
|
||||||
return json.loads(request)['id']
|
return longurl
|
||||||
except Exception as err:
|
except:
|
||||||
self.log.error("ERROR: Failed shortening url: {0} :: {1}".format(longurl, err))
|
self.log.error("ERROR: Failed shortening url: {0}".format(longurl))
|
||||||
return None
|
return longurl
|
||||||
|
|
||||||
def _woeid_lookup(self, lookup):
|
def _woeid_lookup(self, lookup):
|
||||||
"""<location>
|
"""<location>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user