Fix URL shortener, in a way...
This commit is contained in:
parent
93168b57a7
commit
bd3e3d8d84
|
@ -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):
|
def shortURL(url):
|
||||||
try:
|
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:
|
except pyshorteners.exceptions.ShorteningErrorException as e:
|
||||||
print("Error handling %s" % url)
|
print("Error handling %s" % url)
|
||||||
raise
|
print(e)
|
||||||
|
return False
|
Loading…
Reference in a new issue