diff --git a/oa.py b/oa.py index 9a3d48e..c1723c5 100644 --- a/oa.py +++ b/oa.py @@ -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('Name: ')+len("Name: ") - # If no result found - if(beg==len("Name: ")-1): - print "Something went wrong for roll No %d " %i - continue - end=html.find('

',beg) - - print "Roll No :" + str(i) - print "Name : "+html[beg:end].strip() - # Find the hostel info for the current roll number - beg=html.find('Hostel Info: ')+len("Hostel Info: ") - if(beg==len("Hostel Info: ")-1): - print "Roll No %d invalid" %i - continue - end=html.find('
',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 ") + 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('Name: ')+len("Name: ") + # If no result found + if(beg==len("Name: ")-1): + print ("Something went wrong for roll No %d " %i) + print ("\n\n") + continue + end=html.find('

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

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

',beg) + print ("Dept: "+html[beg:end].strip()) + + # Find the hostel info for the current roll number + beg=html.find('Hostel Info: ')+len("Hostel Info: ") + if(beg==len("Hostel Info: ")-1): + print ("Roll No %d invalid" %i) + print ("\n\n") + continue + end=html.find('
',beg) + print ("Address : "+html[beg:end].strip()) + + beg=html.find(' E-Mail: ')+len(" E-Mail: ") + if(beg==len(" E-Mail: ")-1): + print ("Roll No %d invalid" %i) + print ("\n\n") + continue + end=html.find('',beg) + email = re.search('>(.*)', html[beg:end].strip()).group(1) + print ("Email: " + email) + + print ("")