Advertisement
Guest User

New NU Result System

a guest
Oct 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2.  
  3. def getResult(reg, examCode, examYear):
  4.     link='http://www.nu.ac.bd/results/cse/cse_result.php?roll_number=&reg_no={reg}&exm_code={examCode}&exam_year={examYear}'
  5.     r=get(link.format(reg=reg, examCode=examCode, examYear=examYear))
  6.  
  7.     soup=BeautifulSoup(r.text, 'html.parser')
  8.  
  9.     if soup.body.table.tr.td.text=='Error! Wrong Registration Number':
  10.         return {'exception':'student_not_found'}
  11.  
  12.     else:
  13.         fullList,grades=[],{}
  14.  
  15.         resultRows1=soup.find_all('table')[1].findAll('tr')
  16.         resultRows2=soup.find_all('table')[2].findAll('tr')[1:]
  17.  
  18.         name=resultRows1[4].find_all('td')[2].text.strip()
  19.         semester=resultRows1[2].td.text.strip().split()[1].lower()
  20.  
  21.         try:
  22.             cgpa=float(resultRows1[9].find_all('td')[2].text.strip())
  23.         except:
  24.             cgpa=0
  25.  
  26.         for result in resultRows2:
  27.             singleList=[]
  28.             for singleResult in result.find_all('td'):
  29.                 t=singleResult.text.strip()
  30.                 if len(t)==4 and t.isnumeric() and t[0]=='0':
  31.                     t='CSE_'+t[1:]
  32.                 singleList.append(t)
  33.  
  34.             grades[singleList[0]]=singleList[3]
  35.  
  36.             fullList.append(singleList)
  37.  
  38.         finalJson={'batch':int(str(reg)[0:2])-8, 'cgpa': cgpa, 'courses':fullList, 'exam year':examYear,
  39.                    'exception':'result_found', 'grades':grades, 'name':name, 'registration': reg,
  40.                    'result':'PASSED' if cgpa!=0 else 'FAILED', 'semester':semester,
  41.                    'session':'20'+str(reg)[:2]+'-'+str(int(str(reg)[:2])+1)}
  42.  
  43.         return finalJson
  44.  
  45. # Reg Starts With 17 and 2nd Semester Exam Code 5612 and Exam Year 2018
  46. # Reg Starts With 17 and 4th Semester Exam Code 5614 and Exam Year 2018
  47. print(getResult(17502004213, 5612, 2018))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement