Skip to content

Commit 76bc01b

Browse files
committed
valid url check with exception handeling
1 parent 66867a5 commit 76bc01b

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

url_shortner.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
# Importing the required libraries.
22
import pyshorteners
3+
from colorama import Fore # this module for font color
34

45
# Taking input from the user.
56
url = input("Enter URL: ")
67

7-
# Creating an instance of the pyshorteners library.
8-
shortener = pyshorteners.Shortener()
8+
# exception handling
9+
try:
10+
# Creating an instance of the pyshorteners library.
11+
shortener = pyshorteners.Shortener()
912

10-
# Shortening the URL using TinyURL.
11-
shortened_URL = shortener.tinyurl.short(url)
13+
# Shortening the URL using TinyURL.
14+
shortened_URL = shortener.tinyurl.short(url)
15+
16+
# Displaying the shortened URL.
17+
print(f"Shortened URL: {shortened_URL}")
18+
except(Exception) as e:
19+
# this code runes on any error is generated by user
20+
print(Fore.RED, "Enter Valid URL format", Fore.RESET)
1221

13-
# Displaying the shortened URL.
14-
print(f"Shortened URL: {shortened_URL}")

0 commit comments

Comments
 (0)