In a previous post of mine, I have published a php class to generate short urls using the TinyURL API. Here is a simple Python program to generate tiny URLs directly from your desktop.
The File: (Python 3)
|
import sys; from urllib.request import urlopen; url = str(sys.argv[1]); data = urlopen("http://tinyurl.com/api-create.php?url="+url); print(data.readlines()[1].decode()); |
How To use?
Save the file as “tinyurl.py”.
You have to pass a target URL as the only argument to the program. The short url will be printed out on your screen.
Type the following command on your cmd or shell to execute the program.
tinyurl.py https://masnun.com
The short url will be printed out on the screen (shell or cmd).
If you don’t know or like the idea of copying text from the command line interface, simply redirect the output of the program to a text file:
tinyurl.py https://masnun.com > url.txt
The above code will fetch the short URL and put it into the file named “url.txt” 🙂 I use this method.
To Do: I am thinking of adding the functionality to create multiple short url from a single execution.