diff --git a/url_shortner.py b/url_shortner.py new file mode 100644 index 0000000..4a5724f --- /dev/null +++ b/url_shortner.py @@ -0,0 +1,24 @@ +from _future_ import with_statement +import contextlib +try: + from urllib.parse import urlencode +except ImportError: + from urllib import urlencode +try: + from urllib.request import urlopen +except ImportError: + from urllib2 import urlopen +import sys + +def make_tiny(url): + request_url = ('http://tinyurl.com/api-create.php?' + + urlencode({'url':url})) + with contextlib.closing(urlopen(request_url)) as response: + return response.read().decode('utf-8') + +def main(): + urls = input("Enter a URL: ") + print(make_tiny(urls)) + +if _name_ == '_main_': + main()