Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Totally revamped oa script. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 68 additions & 22 deletions oa.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,70 @@
import urllib
import urllib2
for i in range(13000,13800):
# Sending a get request to the URL
html=urllib2.urlopen('http://oa.cc.iitk.ac.in:8181/Oa/Jsp/OAServices/IITk_SrchRes.jsp?typ=stud&numtxt=%d&sbm=Y' %i)
# Reading the response
html=html.read()
# Finding the name for a roll number
beg=html.find('<b>Name: </b>')+len("<b>Name: </b>")
# If no result found
if(beg==len("<b>Name: </b>")-1):
print "Something went wrong for roll No %d " %i
continue
end=html.find('</p>',beg)

print "Roll No :" + str(i)
print "Name : "+html[beg:end].strip()
# Find the hostel info for the current roll number
beg=html.find('<b>Hostel Info: </b>')+len("<b>Hostel Info: </b>")
if(beg==len("<b>Hostel Info: </b>")-1):
print "Roll No %d invalid" %i
continue
end=html.find('<br>',beg)
print "Address : "+html[beg:end].strip()+"\n\n"
import sys
import re

if(len(sys.argv) != 3):
print ("Please run this as: python oa.py <initial> <final>")
print ("Use python2")
exit()

try:
initial = int(sys.argv[1])
final = int(sys.argv[2])+1
assert initial < final

except:
print ("Enter valid roll numbers")

for i in range(initial,final):
# Sending a get request to the URL
html=urllib2.urlopen('http://oa.cc.iitk.ac.in/Oa/Jsp/OAServices/IITk_SrchRes.jsp?typ=stud&numtxt=%d&sbm=Y' %i)
# Reading the response
html=html.read()
# Finding the name for a roll number
beg=html.find('<b>Name: </b>')+len("<b>Name: </b>")
# If no result found
if(beg==len("<b>Name: </b>")-1):
print ("Something went wrong for roll No %d " %i)
print ("\n\n")
continue
end=html.find('</p>',beg)

print ("Roll No :" + str(i))
print ("Name : "+html[beg:end].strip())

beg=html.find('<b>Program: </b>')+len("<b>Program: </b>")
if(beg==len("<b>Program: </b>")-1):
print ("Roll No %d invalid" %i)
print ("\n\n")
continue
end=html.find('</p>',beg)
print ("Program: "+html[beg:end].strip())

beg=html.find('<b>Department: </b>')+len("<b>Department: </b>")
if(beg==len("<b>Department: </b>")-1):
print ("Roll No %d invalid" %i)
print ("\n\n")
continue
end=html.find('</p>',beg)
print ("Dept: "+html[beg:end].strip())

# Find the hostel info for the current roll number
beg=html.find('<b>Hostel Info: </b>')+len("<b>Hostel Info: </b>")
if(beg==len("<b>Hostel Info: </b>")-1):
print ("Roll No %d invalid" %i)
print ("\n\n")
continue
end=html.find('<br>',beg)
print ("Address : "+html[beg:end].strip())

beg=html.find('<b> E-Mail: </b>')+len("<b> E-Mail: </b>")
if(beg==len("<b> E-Mail: </b>")-1):
print ("Roll No %d invalid" %i)
print ("\n\n")
continue
end=html.find('</a>',beg)
email = re.search('>(.*)', html[beg:end].strip()).group(1)
print ("Email: " + email)

print ("")