NTU Course Vacancy Checker

Update 2016: The code is no longer working due to external changes.

#!/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>&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(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()

 

Leave a Reply