A simple command line interface for Bitly written in Python. Shorten URLs or get click statistics for existing bitlinks (shortened links).
You will need an API token to use Bitly via this script.
To obtain it, create an account on Bitly. I recommend signing up with email โ for some reason, getting an API token gets trickier if you create an account using social media.
Confirm your email and then go to Developer settings
and generate an access token. It will be a string looking something like this:
17c09e20ad155405123ac1977542fecf00231da7
.
Create a file named ".env" in the same directory as the script. This is where your API token will be (more or less safely) stored. Add the following line to the file: "BITLY_TOKEN=your_token" (remove the quotation marks). The file will look like this:
BITLY_TOKEN=17c09e20ad155405123ac1977542fecf00231da7
Python3 should be already installed.
Then use pip
(or pip3
, if there is a conflict with Python2) to install dependencies:
$ pip install -r requirements.txt
Optionally, you can use virtualenv to install the packages inside a virtual environment and not on your entire system. In this case you will need to configure running the script from the virtual environment as well.
Open the terminal and run:
$ python3 path/to/the/script/main.py https://long-link.that/you-want?to=shorten
or to get statistics (total clicks) for an existing bitlink:
$ python3 path/to/the/script/main.py bit.ly/link-code
Keep in mind that the script will not shorten links without the URL scheme supplied
(http://
, https://
, etc).