Skip to content

How could we modify the URL_Shortner_App code to allow the user to choose between different URL shortening services? #2

Answered by amark720
nirsa1001 asked this question in Q&A
Discussion options

You must be logged in to vote

To offer multiple services, you could create a menu for the user to choose a preferred service (e.g., TinyURL, Bitly) and then use the corresponding method in pyshorteners. For example:

services = {
    "1": "TinyURL",
    "2": "Bitly",
    "3": "Isgd",
}
print("Choose a URL shortening service:\n1. TinyURL\n2. Bitly\n3. Isgd")
choice = input("Enter the number of your choice: ")
url = input("Enter URL which you want to shorten: \n")

try:
    shortener = pyshorteners.Shortener()
    if choice == "1":
        print("URL After Shortening: ", shortener.tinyurl.short(url))
    elif choice == "2":
        print("URL After Shortening: ", shortener.bitly.short(url))
    elif choice == "3":
      …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nirsa1001
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants