twitools/httptools/__init__.py

13 lines
376 B
Python
Raw Normal View History

2017-03-13 21:55:49 +00:00
import setuptools, pyshorteners, requests
def longURL(url):
return requests.head(url, allow_redirects=True).url
def shortURL(url):
try:
2017-03-13 21:55:49 +00:00
return pyshorteners.Shortener('Google', api_key=setuptools.getSetting("Google", "googl")).short(longURL(url))
except pyshorteners.exceptions.ShorteningErrorException as e:
print("Error handling %s" % url)
2017-03-13 21:55:49 +00:00
print(e)
return False