Coding simple URL Shortener with Python

Is a Python lib to wrap and consume the most used shorteners APIs. Many people use because is fast and anonymous.

Coding an Url Shortner Using Python

Installing

pip install pyshorteners

Coding

import pyshorteners

def shorter(link):
    #create object
    short = pyshorteners.Shortener()
    short_link = short.tinyurl.short(link)
    return short_link

url = input("URL: ")
final = shorter(url)
print(f"Shortened Link is {final}")

#append orginal and final url in a .txt file
file_object = open('urls.txt', 'a')
file_object.write("\n---------------------------------------------\nOriginal Url: " + url + "\nShortened Link is: " + final +"\n")
print("Saved in urls.txt")

run the code
python short_url.py

Output


URL: https://peakd.com/c/hive-169321/created
Shortened Link is https://tinyurl.com/yf7jaf46
Saved in urls.txt

Text File (urls.txt)

---------------------------------------------
Original Url: https://peakd.com/c/hive-169321/created
Shortened Link is: https://tinyurl.com/yf7jaf46

I code this just for fun, now I'm creating a lot of content on blockchain dapps and web development so I think this code could be very useful for people who don't use interfaces and prefer to do everything in a python script.


foto-perfil-peakd-viviendo-libre-superbaja.png

Encuéntrame aquí:

Peakd

DTube

Odysee

Youtube

Instagram

H2
H3
H4
3 columns
2 columns
1 column
2 Comments
Ecency