12 lines
375 B
Python
12 lines
375 B
Python
import setuptools, pyshorteners, requests
|
|
|
|
def longURL(url):
|
|
return requests.get(url, allow_redirects=True).url
|
|
|
|
def shortURL(url):
|
|
try:
|
|
return pyshorteners.Shortener('Google', api_key=setuptools.getSetting("Google", "googl")).short(longURL(url))
|
|
except pyshorteners.exceptions.ShorteningErrorException as e:
|
|
print("Error handling %s" % url)
|
|
print(e)
|
|
return False
|