├── config.default.js ├── README.md ├── .gitignore ├── package.json ├── LICENSE ├── index.js ├── util.js ├── studentInfo.js ├── login.js └── course.js /config.default.js: -------------------------------------------------------------------------------- 1 | /* Course Planner 2 | * config file 3 | */ 4 | 5 | module.exports = { 6 | netID: '', 7 | password: '', 8 | debug: false 9 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoursePlanner 2 | for UIUC 3 | 4 | ### Environment 5 | ``` 6 | # install node 6.2.0 and npm first 7 | 8 | # install the dependencies 9 | $ npm install 10 | ``` 11 | 12 | ### How 13 | 1. Duplicate the `config.default.js` and rename it into `config.js`. Modify the information. 14 | ``` 15 | module.exports = { 16 | netID: '', // Type in your NetID here 17 | password: '', // Your password 18 | debug: false 19 | } 20 | ``` 21 | 22 | 2. Run 23 | ``` 24 | npm run getcourselist 25 | npm run getstudentinfo 26 | ``` 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | 35 | # config 36 | config.js 37 | *.temp -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "courseplanner", 3 | "version": "1.0.0", 4 | "description": "for UIUC", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "getcourselist": "node index.js getcourselist", 9 | "getstudentinfo": "node index.js getstudentinfo" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://rijn@github.com/rijn/CoursePlanner.git" 14 | }, 15 | "author": "Rijn", 16 | "license": "MIT", 17 | "bugs": { 18 | "url": "https://github.com/rijn/CoursePlanner/issues" 19 | }, 20 | "homepage": "https://github.com/rijn/CoursePlanner#readme", 21 | "dependencies": { 22 | "colors": "^1.1.2", 23 | "cookie": "^0.2.4", 24 | "htmlparser2": "^3.9.0", 25 | "http": "0.0.0", 26 | "md5": "^2.1.0", 27 | "q": "^1.4.1", 28 | "querystring": "^0.2.0", 29 | "request": "^2.72.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Rijn Bian 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // get arguments 2 | 3 | var arguments = process.argv.splice(2); 4 | console.log(arguments); 5 | 6 | const util = require('./util'); 7 | var config = util.getConfig(); 8 | 9 | console.log('User config = ', config); 10 | 11 | // include dependencies 12 | 13 | const Q = require('q'); 14 | const colors = require('colors'); 15 | 16 | util.colorSetTheme(colors); 17 | 18 | var sharedObject = { 19 | 'cookie': [] 20 | }; 21 | 22 | var login = require('./login'); 23 | var studentInfo = require('./studentInfo'); 24 | var course = require('./course'); 25 | 26 | console.log('\nrunning...'.warn); 27 | 28 | switch (arguments[0]) { 29 | case 'getstudentinfo': 30 | login.login(sharedObject) 31 | .then(studentInfo.getStudentInfoTermList) 32 | .then(studentInfo.requestStudentInfo) 33 | .then(null, util.throwErr) 34 | .done(); 35 | break; 36 | case 'getcourselist': 37 | login.login(sharedObject) 38 | .then(studentInfo.getStudentInfoTermList) 39 | .then(course.getSubjectList) 40 | .then(course.getCourseList) 41 | .then(course.parseCourseList) 42 | .then(course.writeTree) 43 | .then(course.generateCourseCodeList) 44 | .then(null, util.throwErr) 45 | .done(); 46 | break; 47 | } 48 | -------------------------------------------------------------------------------- /util.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 3 | combineCookies: function(newCookie, sharedObject) { 4 | if (newCookie) { 5 | for (var i = 0; i < newCookie.length; i++) { 6 | newCookie[i] = newCookie[i].split(';')[0]; 7 | } 8 | } 9 | for (var i in newCookie) { 10 | var key = newCookie[i].split('=')[0]; 11 | for (var j = 0; j < sharedObject.cookie.length; j++) { 12 | if (sharedObject.cookie[j].indexOf(key) >= 0) { 13 | sharedObject.cookie[j] = newCookie[i]; 14 | key = 'COOKIEFLAG'; 15 | } 16 | } 17 | if (key != 'COOKIEFLAG') { 18 | sharedObject.cookie.push(newCookie[i]); 19 | } 20 | } 21 | }, 22 | 23 | getConfig: function() { 24 | var defaultConfig = require('./config.default'); 25 | var config = defaultConfig; 26 | 27 | var arguments = process.argv.splice(2); 28 | 29 | try { 30 | var userConfig = require('./config'); 31 | } catch (e) { 32 | console.log('Could not find user config'); 33 | return; 34 | } 35 | 36 | for (var i in defaultConfig) { 37 | if (userConfig.hasOwnProperty(i)) { 38 | config[i] = userConfig[i]; 39 | } 40 | } 41 | 42 | return config; 43 | }, 44 | 45 | throwErr: function(err) { 46 | const colors = require('colors'); 47 | console.log('\n', err.red); 48 | throw err; 49 | }, 50 | 51 | colorSetTheme: function(colors) { 52 | colors.setTheme({ 53 | info: 'green', 54 | data: 'grey', 55 | help: 'cyan', 56 | warn: 'yellow', 57 | debug: 'blue', 58 | error: 'red', 59 | request: 'cyan', 60 | result: 'green', 61 | }); 62 | }, 63 | }; 64 | -------------------------------------------------------------------------------- /studentInfo.js: -------------------------------------------------------------------------------- 1 | const https = require('https'); 2 | const Q = require('q'); 3 | const querystring = require('querystring'); 4 | const colors = require('colors'); 5 | 6 | const util = require('./util'); 7 | var config = util.getConfig(); 8 | 9 | util.colorSetTheme(colors); 10 | 11 | module.exports = { 12 | 13 | getStudentInfoTermList: function(sharedObject) { 14 | var deferred = Q.defer(); 15 | 16 | var options = { 17 | hostname: 'ui2web1.apps.uillinois.edu', 18 | port: 443, 19 | path: '/BANPROD1/bwskgstu.P_StuInfo', 20 | method: 'GET', 21 | headers: { 22 | 'Host': 'ui2web1.apps.uillinois.edu', 23 | 'Upgrade-Insecure-Requests': 1, 24 | 'Cookie': sharedObject.cookie.join(';'), 25 | 'User-Agent': 'Paw/2.1 (Macintosh; OS X/10.10.1) GCDHTTPRequest', 26 | 'Referer': 'https://ui2web1.apps.uillinois.edu/BANPROD1/twbkwbis.P_GenMenu?name=bmenu.P_AdminMnu', 27 | } 28 | }; 29 | 30 | console.log('\nREQUEST'.request, options.hostname + options.path); 31 | 32 | var data = ''; 33 | 34 | var req = https.request(options, (res) => { 35 | console.log('STATUS'.result, res.statusCode); 36 | if (config.debug) { 37 | console.log('HEADERS'.data, res.headers); 38 | } 39 | 40 | res.on('data', (d) => { 41 | data += d; 42 | // process.stdout.write(d); 43 | }); 44 | 45 | res.on('end', () => { 46 | util.combineCookies(res.headers['set-cookie'], sharedObject); 47 | // console.log('DATA'.data, data.data); 48 | var regexp = /\