Last active
October 17, 2022 18:19
-
-
Save Abhayparashar31/e3e2e7d4baf62cb0fb2ea0a810189468 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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(): | |
for tinyurl in map(make_tiny, sys.argv[1:]): | |
print(tinyurl) | |
if __name__ == '__main__': | |
main() |
This code worked for me with the command python3 filename.py url
This code isn't running for me..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code isn't running for me..