Skip to content

Commit dfe2dac

Browse files
Merge pull request #3063 from mr-d-luffy/mr-temp
use of json with loop for index
2 parents 72351a9 + 76bc01b commit dfe2dac

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

Web Socket.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# Program to print a data & it's Metadata of online uploaded file using "socket".
22
import socket
3-
skt_c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
4-
skt_c.connect(("data.pr4e.org", 80))
5-
link = "GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n".encode()
6-
skt_c.send(link)
3+
from colorama import Fore # this module for Color the font
4+
5+
# handling the exceptions
6+
try:
7+
skt_c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
8+
skt_c.connect(("data.pr4e.org", 80))
9+
link = "GET http://data.pr4e.org/intro-short.txt HTTP/1.0\r\n\r\n".encode()
10+
skt_c.send(link)
11+
except(Exception) as e:
12+
# this code runes on error in any connection
13+
print(Fore.RED, e, Fore.RESET)
714

815
while True:
916
data = skt_c.recv(512)

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}")

write_excel_file.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
1-
import xlwt
2-
import openpyxl
1+
import xlwt # type: ignore
2+
import openpyxl # type: ignore
33

44
# Workbook is created
55
xlwt_wb = xlwt.Workbook()
66

7+
"""
8+
we can also use of json object format for this file or code,
9+
for the index we can use (for loop) and for data use json object.
10+
example of json object:
11+
{
12+
"data":[
13+
"ISBT DEHRADUN".
14+
"SHASTRADHARA",
15+
"CLEMEN TOWN",
16+
"RAJPUR ROAD",
17+
"CLOCK TOWER",
18+
"ISBT DEHRADUN",
19+
"SHASTRADHARA",
20+
"CLEMEN TOWN",
21+
"RAJPUR ROAD",
22+
"CLOCK TOWER"
23+
]
24+
}
25+
"""
26+
727
# add_sheet is used to create sheet.
828
sheet1 = xlwt_wb.add_sheet("Sheet 1")
929

0 commit comments

Comments
 (0)