Update 2016: The code is no longer working due to external changes.
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 |
#!/usr/local/bin/python3 """NTU Course Vacancy Checker, written by @yuan3y (Twitter/Instagram) Source code available at: http://snipt.org/BCgh2 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""" 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> </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(subj,lines[i+3],lines[i+6],lines[i+9],'='+str(int(lines[i+9]))+'/'+str(int(lines[i+6])),lines[i+12],lines[i+15],lines[i+18]+lines[i+21],lines[i+24],sep=',',end=”) print(subj, 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 while True: courseList = [] while True: a = input('course, @ to end:') courseList.extend(a.split()) if '@' in a: break for courseCode in courseList: check(courseCode.strip()) print() |