#! /usr/bin/python

import json
import random
import os

print 'Content-type: application/javascript'
print

callbackFunc = 'updateCourses'
if 'QUERY_STRING' in os.environ:
    qs = os.environ['QUERY_STRING']
    if (qs.startswith('callback=')):
        callbackFunc = qs[9:]
deptChoice = [ 'CSCI', 'CSCI', 'NM  ' ]
numentries = random.randint(0, 31)
out = [ ]
for x in range(1, random.randint(0, 32)):
    dept = deptChoice[random.randint(0,2)]
    number = 101 + 15*random.randint(0,36)
    if (random.randint(0,5) < 5):
        section = "00" + str(random.randint(0,5))
    else:
        section = "0L" + str(random.randint(0,9))
    info  = {'dept' : dept, 'number' : number, 'section' : section}
    out.append(info)

print callbackFunc + '(' + json.dumps(out) + ');'

