forked from Harshsngh07/Hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# A python program to use TinyURL to shorten an given URL | ||
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 | ||
|
||
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(): | ||
url = input() | ||
print(make_tiny(url)) | ||
|
||
if __name__ == '__main__': | ||
main() |