18 December 2013

NTU Course Vacancy Checker

#!/usr/local/bin/python3 '''NTU Course Vacancy Checker, written by @yuan3y (Twitter/Instagram) You will need a Python 3 interpreter to run this code: Such as http://www.python.org/download/releases/3.3.3/ Type in your subject codes each on a line, ends off with a single @ sign on a separate line. Merry Christmas and happy STARS games! God bless, @yuan3y 18 DEC 2013''' courseList=[] while True: a=input('course, @ to end:') courseList.extend(a.split()) if '@' in a: break import urllib.parse import urllib.request def check(subj): url = 'http://wish.wis.ntu.edu.sg/webexe/owa/aus_vacancy.check_vacancy2' values = {'subj' : subj} headers = {'Referer' : 'http://wish.wis.ntu.edu.sg/webexe/owa/aus_vacancy.check_vacancy'} data = urllib.parse.urlencode(values) data = data.encode('utf-8') req = urllib.request.Request(url, data, headers) response = urllib.request.urlopen(req) the_page = response.read() lines=the_page.decode().split('\n') for i, a in enumerate(lines): if '</TR>' in a: break try: print('\n',subj,end='') while True: if '<td>&NBSP;</td>' in lines[i+2]: print('',lines[i+6],lines[i+9],lines[i+12],lines[i+15],lines[i+18],sep=',',end='') i+=20 else: print() print(lines[i+3],lines[i+6],lines[i+9],lines[i+12],lines[i+15],lines[i+18],lines[i+21],lines[i+24],sep=',',end='') i+=26 if '</TABLE>' in lines[i+1]: break except: pass finally: print() for courseCode in courseList: check(courseCode)
# code can be downloaded from: http://snipt.org/BCgh2

# interpreter can be downloaded from: http://www.python.org/download/releases/3.3.3/

No comments:

Post a Comment