-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch.py
executable file
·143 lines (127 loc) · 3.95 KB
/
search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env python3
"""
A python3 script to search student info from iitk database
"""
import urllib.request
import time
def parse_name(page):
"""
Extracts name from the page
"""
name = page.split("<b>Name: </b>\\r\\n\\t\\t\\t\\t\\t\\t"
+ "\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t")[1]
name = name.split("\\r\\n")[0]
return name
def parse_program(page):
"""
Parses the program - B.Tech, M.Tech...
"""
program = page.split("<b>Program: </b>\\r\\n\\t\\t\\t\\t\\t\\t\\t"
+ "\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t")[1]
program = program.split("\\r\\n")[0]
return program
def parse_department(page):
"""
Parses the department
"""
dep = page.split("<b>Department: </b>\\r\\n\\t\\t\\t\\t\\t\\t\\t"
+ "\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t")[1]
dep = dep.split("\\r\\n")[0]
return dep
def parse_address(page):
"""
Gets the hostel info
"""
hostelinf = page.split("<b>Hostel Info: </b>\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t"
+ "\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t")[1]
hostelinf = hostelinf.split("\\r\\n")[0]
hall = hostelinf.split(",")[0]
room = hostelinf.split(",")[1]
return hall, room
def parse_mail(page):
"""
Gets mailing information
"""
mail = page.split("mailto:")[1].split("\"")[0]
return mail
def parse_blood_group(page):
"""
Gets the blood group
"""
bldgrp = page.split("<b> Blood Group:</b>\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t"
+ "\\t\\t\\t\\t\\t\\t\\t\\t\\t")[1]
bldgrp = bldgrp.split("\\r\\n")[0]
return bldgrp
def parse_category(page):
"""
Gets the category
"""
cat = page.split("Category:</b>")[1].split("<")[0]
return cat
def parse_gender(page):
"""
Gets the gender
"""
gend = page.split("<b> Gender:</b>\\r\\n\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t\\t"
+ "\\t\\t\\t\\t\\t\\t\\t")[1].split("\\r\\n")[0]
return gend
def parse_father_name(page):
"""
Extracts father's name
"""
father_name = page.split("<b>Permanent Address :</b>")[1].split("<br>")[0]
return father_name
def parse_home_address(page):
"""
Extracts home address and number
"""
perm = page.split("<b>Permanent Address :</b>")[1].split("<br>")[1]
perm = perm.split("<br>")[0]
arr = perm.split(",")
index = len(arr)
hometown = arr[index-3] + "," + arr[index-2]
phone = page.split("Phone no:")[2].split("<")[0]
mobile = page.split("Mobile no:")[2].split("<")[0]
return (perm, hometown, phone, mobile)
def get_page(roll):
"""
Gets the entire page from iitk servers
"""
document = urllib.request.urlopen("http://oa.cc.iitk.ac.in/Oa/Jsp/"
+ "OAServices/IITk_SrchRes1.jsp?"
+ "typ=stud&numtxt="
+ str(roll) + "&sbm=Y")
page = str(document.read())
return page
def parse_data(page):
"""
Parses data from the page
"""
print("Name : " + parse_name(page))
print("Gender : " + parse_gender(page))
print("Email : " + parse_mail(page))
print("Program : " + parse_program(page))
print("Dep : " + parse_department(page))
(hall, room) = parse_address(page)
print("Hall : " + hall)
print("Room : " + room)
print("Blood Group : " + parse_blood_group(page))
print("Category : " + parse_category(page))
print("\n Father's Name : \n\t" + parse_father_name(page))
(perm, hometown, phone, mobile) = parse_home_address(page)
print("\n Address : \n\t" + perm)
print("\n Hometown : \n\t" + hometown)
print("\nPhone : " + phone)
print("Mobile : " + mobile)
def main():
"""
The main function to handle it
"""
roll = input("Roll no : ")
page = get_page(roll)
print("Connection Successful")
time.sleep(.3)
print("Roll : " + roll)
parse_data(page)
if __name__ == '__main__':
main()