Fix URL shortener, in a way...

This commit is contained in:
Klaus-Uwe Mitterer 2017-03-13 22:55:49 +01:00
parent 93168b57a7
commit bd3e3d8d84

View file

@ -1,8 +1,12 @@
import setuptools, pyshorteners
import setuptools, pyshorteners, requests
def longURL(url):
return requests.head(url, allow_redirects=True).url
def shortURL(url):
try:
return pyshorteners.Shortener('Google', api_key=setuptools.getSetting("Google", "googl")).short(url)
return pyshorteners.Shortener('Google', api_key=setuptools.getSetting("Google", "googl")).short(longURL(url))
except pyshorteners.exceptions.ShorteningErrorException as e:
print("Error handling %s" % url)
raise
print(e)
return False