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.
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.
Encuéntrame aquí:
Peakd
DTube
Odysee
Youtube
0
0
0.000
That's a cool little project. I've never worked with Python before but it's a cool programming language that you can do a lot with even though it's very simple. I think I should start with Python too :)
never is to late to start coding @jongartv
I like a lot the potential of python, easy syntax and a lot of support from communities.
In fact, is my favorite programming language for personal development.
you can do anything with programming