diff --git a/Web Socket.py b/Web Socket.py index 9c3c91beafa..ed1a32ca08a 100644 --- a/Web Socket.py +++ b/Web Socket.py @@ -1,9 +1,16 @@ # Program to print a data & it's Metadata of online uploaded file using "socket". import socket -skt_c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -skt_c.connect(("data.pr4e.org", 80)) -link = "GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n".encode() -skt_c.send(link) +from colorama import Fore # this module for Color the font + +# handling the exceptions +try: + skt_c = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + skt_c.connect(("data.pr4e.org", 80)) + link = "GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n".encode() + skt_c.send(link) +except(Exception) as e: + # this code runes on error in any connection + print(Fore.RED, e, Fore.RESET) while True: data = skt_c.recv(512) diff --git a/url_shortner.py b/url_shortner.py index 0631a4bdb60..05e13d76721 100644 --- a/url_shortner.py +++ b/url_shortner.py @@ -1,14 +1,21 @@ # Importing the required libraries. import pyshorteners +from colorama import Fore # this module for font color # Taking input from the user. url = input("Enter URL: ") -# Creating an instance of the pyshorteners library. -shortener = pyshorteners.Shortener() +# exception handling +try: + # Creating an instance of the pyshorteners library. + shortener = pyshorteners.Shortener() -# Shortening the URL using TinyURL. -shortened_URL = shortener.tinyurl.short(url) + # Shortening the URL using TinyURL. + shortened_URL = shortener.tinyurl.short(url) + + # Displaying the shortened URL. + print(f"Shortened URL: {shortened_URL}") +except(Exception) as e: + # this code runes on any error is generated by user + print(Fore.RED, "Enter Valid URL format", Fore.RESET) -# Displaying the shortened URL. -print(f"Shortened URL: {shortened_URL}") diff --git a/write_excel_file.py b/write_excel_file.py index 10bfe86044a..8b710503555 100644 --- a/write_excel_file.py +++ b/write_excel_file.py @@ -1,9 +1,29 @@ -import xlwt -import openpyxl +import xlwt # type: ignore +import openpyxl # type: ignore # Workbook is created xlwt_wb = xlwt.Workbook() +""" +we can also use of json object format for this file or code, +for the index we can use (for loop) and for data use json object. +example of json object: +{ + "data":[ + "ISBT DEHRADUN". + "SHASTRADHARA", + "CLEMEN TOWN", + "RAJPUR ROAD", + "CLOCK TOWER", + "ISBT DEHRADUN", + "SHASTRADHARA", + "CLEMEN TOWN", + "RAJPUR ROAD", + "CLOCK TOWER" + ] +} +""" + # add_sheet is used to create sheet. sheet1 = xlwt_wb.add_sheet("Sheet 1")