Courseography/courseography — pull request #235 by Ian-Stewart-Binks (2014-12-31 02:26:25+00:00)
Title: Json response

This pull request extends the JSON response feature that @david-yz-liu and I started on Saturday. It continues to parse JSON objects from the files in `courseography/res/courses` and insert them into a database, and now, given a request to the server, queries a given course in the database and responds with the corresponding JSON object.

This feature is not yet done, however I have decided to make an intermediate pull request to get feedback on the current code and on the direction that I am taking. It is the same direction that we discussed on Saturday, @david-yz-liu, however you may now see it partially realized in the code. I will begin to shorten the time between pull requests from now on.

The parser now accounts for Y sessions, and does a much better job of producing the JSON response.

[Here is the example for the JSON diff between the parsed file and the output file for CSC108H1.](http://tlrobinson.net/projects/javascript-fun/jsondiff/#%7B%22d%22%3A%7B%22a%22%3A%22%7B%5C%22breadth%5C%22%3A%20%5C%22The%20Physical%20and%20Mathematical%20Universes%20(5)%5C%22%2C%20%5C%22description%5C%22%3A%20%5C%22Structure%20of%20computers%3B%20the%20computing%20environment.%20Programming%20in%20a%20language%20such%20as%20Python.%20Program%20structure%3A%20elementary%20data%20types%2C%20statements%2C%20control%20flow%2C%20functions%2C%20classes%2C%20objects%2C%20methods%2C%20fields.%20Lists%3B%20searching%2C%20sorting%20and%20complexity.%20Practical%20(P)%20sections%20consist%20of%20supervised%20work%20in%20the%20computing%20laboratory.%20These%20sections%20are%20offered%20when%20facilities%20are%20available%2C%20and%20attendance%20is%20required.NOTE%3A%20You%20may%20not%20take%20this%20course%20after%20or%20concurrently%20withCSC148H1%2C%20but%20you%20may%20takeCSC148H1afterCSC108H1.%5C%22%2C%20%5C%22title%5C%22%3A%20%5C%22Introduction%20to%20Computer%20Programming%5C%22%2C%20%5C%22prereqString%5C%22%3A%20null%2C%20%5C%22F%5C%22%3A%20%7B%5C%22tutorials%5C%22%3A%20%5B%5D%2C%20%5C%22lectures%5C%22%3A%20%5B%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L0101%5C%22%2C%20%5C%22cap%5C%22%3A%20220%2C%20%5C%22time_str%5C%22%3A%20%5C%22Online%20Web%20Version%5C%22%2C%20%5C%22time%5C%22%3A%20%5B%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Gries%5C%22%2C%20%5C%22enrol%5C%22%3A%20106%2C%20%5C%22wait%5C%22%3A%200%7D%2C%20%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L0201%5C%22%2C%20%5C%22cap%5C%22%3A%20220%2C%20%5C%22wait%5C%22%3A%2013%2C%20%5C%22time%5C%22%3A%20%5B%5B0%2C%2010%5D%2C%20%5B2%2C%2010%5D%2C%20%5B4%2C%2010%5D%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Campbell%5C%22%2C%20%5C%22enrol%5C%22%3A%20220%2C%20%5C%22time_str%5C%22%3A%20%5C%22MWF10%5C%22%7D%2C%20%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L0202%5C%22%2C%20%5C%22cap%5C%22%3A%20220%2C%20%5C%22time_str%5C%22%3A%20%5C%22MWF10%5C%22%2C%20%5C%22time%5C%22%3A%20%5B%5B0%2C%2010%5D%2C%20%5B2%2C%2010%5D%2C%20%5B4%2C%2010%5D%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Fairgrieve%5C%22%2C%20%5C%22enrol%5C%22%3A%20172%2C%20%5C%22wait%5C%22%3A%200%7D%2C%20%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L0301%5C%22%2C%20%5C%22cap%5C%22%3A%20220%2C%20%5C%22wait%5C%22%3A%203%2C%20%5C%22time%5C%22%3A%20%5B%5B0%2C%2013%5D%2C%20%5B2%2C%2013%5D%2C%20%5B4%2C%2013%5D%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Fairgrieve%5C%22%2C%20%5C%22enrol%5C%22%3A%20220%2C%20%5C%22time_str%5C%22%3A%20%5C%22MWF1%5C%22%7D%2C%20%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L5101%5C%22%2C%20%5C%22cap%5C%22%3A%20250%2C%20%5C%22time_str%5C%22%3A%20%5C%22W6-9%5C%22%2C%20%5C%22time%5C%22%3A%20%5B%5B2%2C%2018%5D%2C%20%5B2%2C%2019%5D%2C%20%5B2%2C%2020%5D%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Campbell%5C%22%2C%20%5C%22enrol%5C%22%3A%20208%2C%20%5C%22wait%5C%22%3A%200%7D%5D%7D%2C%20%5C%22prep%5C%22%3A%20null%2C%20%5C%22S%5C%22%3A%20%7B%5C%22tutorials%5C%22%3A%20%5B%5D%2C%20%5C%22lectures%5C%22%3A%20%5B%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L0101%5C%22%2C%20%5C%22cap%5C%22%3A%20220%2C%20%5C%22wait%5C%22%3A%200%2C%20%5C%22time%5C%22%3A%20%5B%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Campbell%5C%22%2C%20%5C%22enrol%5C%22%3A%2055%2C%20%5C%22time_str%5C%22%3A%20%5C%22Online%20Web%20Version%5C%22%7D%2C%20%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L0201%5C%22%2C%20%5C%22cap%5C%22%3A%20220%2C%20%5C%22time_str%5C%22%3A%20%5C%22MWF10%5C%22%2C%20%5C%22time%5C%22%3A%20%5B%5B0%2C%2010%5D%2C%20%5B2%2C%2010%5D%2C%20%5B4%2C%2010%5D%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Fairgrieve%5C%22%2C%20%5C%22enrol%5C%22%3A%2076%2C%20%5C%22wait%5C%22%3A%200%7D%2C%20%7B%5C%22extra%5C%22%3A%200%2C%20%5C%22section%5C%22%3A%20%5C%22L5101%5C%22%2C%20%5C%22cap%5C%22%3A%20250%2C%20%5C%22wait%5C%22%3A%200%2C%20%5C%22time%5C%22%3A%20%5B%5B2%2C%2018%5D%2C%20%5B2%2C%2019%5D%2C%20%5B2%2C%2020%5D%5D%2C%20%5C%22instructor%5C%22%3A%20%5C%22Fairgrieve%5C%22%2C%20%5C%22enrol%5C%22%3A%2079%2C%20%5C%22time_str%5C%22%3A%20%5C%22W6-9%5C%22%7D%5D%7D%2C%20%5C%22prereqs%5C%22%3A%20null%2C%20%5C%22distribution%5C%22%3A%20%5C%22This%20is%20a%20Science%20course%5C%22%2C%20%5C%22manualTutorialEnrolment%5C%22%3A%20false%2C%20%5C%22exclusions%5C%22%3A%20null%2C%20%5C%22name%5C%22%3A%20%5C%22CSC108H1%5C%22%7D%22%2C%22b%22%3A%22%7B%5C%22prereqString%5C%22%3Anull%2C%5C%22distribution%5C%22%3A%5C%22This%20is%20a%20Science%20course%5C%22%2C%5C%22prereqs%5C%22%3Anull%2C%5C%22breadth%5C%22%3A%5C%22The%20Physical%20and%20Mathematical%20Universes%20(5)%5C%22%2C%5C%22name%5C%22%3A%5C%22CSC108H1%5C%22%2C%5C%22exclusions%5C%22%3Anull%2C%5C%22title%5C%22%3A%5C%22Introduction%20to%20Computer%20Programming%5C%22%2C%5C%22S%5C%22%3A%7B%5C%22lectures%5C%22%3A%5B%7B%5C%22cap%5C%22%3A220%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5D%2C%5C%22instructor%5C%22%3A%5C%22Campbell%5C%22%2C%5C%22wait%5C%22%3A0%2C%5C%22time_str%5C%22%3A%5C%22Online%20Web%20Version%5C%22%2C%5C%22enrol%5C%22%3A55%2C%5C%22section%5C%22%3A%5C%22L0101%5C%22%7D%2C%7B%5C%22cap%5C%22%3A220%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5B0%2C10%5D%2C%5B2%2C10%5D%2C%5B4%2C10%5D%5D%2C%5C%22instructor%5C%22%3A%5C%22Fairgrieve%5C%22%2C%5C%22wait%5C%22%3A0%2C%5C%22time_str%5C%22%3A%5C%22MWF10%5C%22%2C%5C%22enrol%5C%22%3A76%2C%5C%22section%5C%22%3A%5C%22L0201%5C%22%7D%2C%7B%5C%22cap%5C%22%3A250%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5B2%2C18%5D%2C%5B2%2C19%5D%2C%5B2%2C20%5D%5D%2C%5C%22instructor%5C%22%3A%5C%22Fairgrieve%5C%22%2C%5C%22wait%5C%22%3A0%2C%5C%22time_str%5C%22%3A%5C%22W6-9%5C%22%2C%5C%22enrol%5C%22%3A79%2C%5C%22section%5C%22%3A%5C%22L5101%5C%22%7D%5D%2C%5C%22tutorials%5C%22%3A%5B%5D%7D%2C%5C%22manualTutorialEnrolment%5C%22%3Anull%2C%5C%22description%5C%22%3A%5C%22Structure%20of%20computers%3B%20the%20computing%20environment.%20Programming%20in%20a%20language%20such%20as%20Python.%20Program%20structure%3A%20elementary%20data%20types%2C%20statements%2C%20control%20flow%2C%20functions%2C%20classes%2C%20objects%2C%20methods%2C%20fields.%20Lists%3B%20searching%2C%20sorting%20and%20complexity.%20Practical%20(P)%20sections%20consist%20of%20supervised%20work%20in%20the%20computing%20laboratory.%20These%20sections%20are%20offered%20when%20facilities%20are%20available%2C%20and%20attendance%20is%20required.NOTE%3A%20You%20may%20not%20take%20this%20course%20after%20or%20concurrently%20withCSC148H1%2C%20but%20you%20may%20takeCSC148H1afterCSC108H1.%5C%22%2C%5C%22F%5C%22%3A%7B%5C%22lectures%5C%22%3A%5B%7B%5C%22cap%5C%22%3A220%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5D%2C%5C%22instructor%5C%22%3A%5C%22Gries%5C%22%2C%5C%22wait%5C%22%3A0%2C%5C%22time_str%5C%22%3A%5C%22Online%20Web%20Version%5C%22%2C%5C%22enrol%5C%22%3A106%2C%5C%22section%5C%22%3A%5C%22L0101%5C%22%7D%2C%7B%5C%22cap%5C%22%3A220%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5B0%2C10%5D%2C%5B2%2C10%5D%2C%5B4%2C10%5D%5D%2C%5C%22instructor%5C%22%3A%5C%22Campbell%5C%22%2C%5C%22wait%5C%22%3A13%2C%5C%22time_str%5C%22%3A%5C%22MWF10%5C%22%2C%5C%22enrol%5C%22%3A220%2C%5C%22section%5C%22%3A%5C%22L0201%5C%22%7D%2C%7B%5C%22cap%5C%22%3A220%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5B0%2C10%5D%2C%5B2%2C10%5D%2C%5B4%2C10%5D%5D%2C%5C%22instructor%5C%22%3A%5C%22Fairgrieve%5C%22%2C%5C%22wait%5C%22%3A0%2C%5C%22time_str%5C%22%3A%5C%22MWF10%5C%22%2C%5C%22enrol%5C%22%3A172%2C%5C%22section%5C%22%3A%5C%22L0202%5C%22%7D%2C%7B%5C%22cap%5C%22%3A220%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5B0%2C13%5D%2C%5B2%2C13%5D%2C%5B4%2C13%5D%5D%2C%5C%22instructor%5C%22%3A%5C%22Fairgrieve%5C%22%2C%5C%22wait%5C%22%3A3%2C%5C%22time_str%5C%22%3A%5C%22MWF1%5C%22%2C%5C%22enrol%5C%22%3A220%2C%5C%22section%5C%22%3A%5C%22L0301%5C%22%7D%2C%7B%5C%22cap%5C%22%3A250%2C%5C%22extra%5C%22%3A0%2C%5C%22time%5C%22%3A%5B%5B2%2C18%5D%2C%5B2%2C19%5D%2C%5B2%2C20%5D%5D%2C%5C%22instructor%5C%22%3A%5C%22Campbell%5C%22%2C%5C%22wait%5C%22%3A0%2C%5C%22time_str%5C%22%3A%5C%22W6-9%5C%22%2C%5C%22enrol%5C%22%3A208%2C%5C%22section%5C%22%3A%5C%22L5101%5C%22%7D%5D%2C%5C%22tutorials%5C%22%3A%5B%5D%7D%2C%5C%22Y%5C%22%3A%7B%5C%22lectures%5C%22%3A%5B%5D%2C%5C%22tutorials%5C%22%3A%5B%5D%7D%7D%22%7D%7D)

Of course, this is CSC108 which is a fairly tame course. There are other courses that are currently not working as well as CSC108H1.

There are adjustments that I need to make, and I will be making them in the coming days. If you have any concerns or suggestions, please feel free to comment on the pull request.

[Note that with some small tweaks to the JSON (changing the case of the first letter for fields that begin with an upper-case letter to a lower case letter such that their name can be mirrored in the corresponding struct in Haskell).](https://www.fpcomplete.com/school/starting-with-haskell/libraries-and-frameworks/text-manipulation/json#step-2--the-smart-alternative)