From bd3e3d8d847ca22cd264659ca4138430ddf052ba Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Mon, 13 Mar 2017 22:55:49 +0100 Subject: [PATCH] Fix URL shortener, in a way... --- {googletools => httptools}/__init__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) rename {googletools => httptools}/__init__.py (50%) diff --git a/googletools/__init__.py b/httptools/__init__.py similarity index 50% rename from googletools/__init__.py rename to httptools/__init__.py index b4891a9..e0a4da9 100644 --- a/googletools/__init__.py +++ b/httptools/__init__.py @@ -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