Created
June 19, 2017 04:00
-
-
Save evanlimanto/e753a0a00e515fa8f712b13dd6c9ae44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const _ = require('lodash'); | |
const fs = require('fs'); | |
const http = require('http'); | |
const courses = [ | |
"ACTSC", | |
"AFM", | |
"AMATH", | |
"BIOL", | |
"CHEM", | |
"CM", | |
"CO", | |
"CS", | |
"ECE", | |
"ECON", | |
"HRM", | |
"MATH", | |
"MSCI", | |
"PHYS", | |
"PMATH", | |
"SCI", | |
"SE", | |
"STAT", | |
]; | |
const numbers = _.range(100, 1000); | |
const items = _.flatten(_.map(courses, (course) => { | |
return _.map(numbers, (number) => { | |
return [course, number]; | |
}); | |
})); | |
const async = require('async'); | |
const request = require('request'); | |
const options = { | |
url: "https://cas.uwaterloo.ca/cas/login?service=http%3A%2F%2Fmathsoc.uwaterloo.ca%2Fexambank", | |
method: "POST", | |
form: { | |
username: "asdf", | |
password: "asdf", | |
}, | |
jar: true, | |
}; | |
/* | |
const file = fs.createWriteStream("file.pdf"); | |
http.get("http://storage.googleapis.com/studyform/ucberkeley/pdf/ee16a/mt1-fa16-soln.pdf", (res) => { | |
res.pipe(file); | |
}); | |
*/ | |
request(options, (err, response, body) => { | |
return async.forEach(items, (item, callback) => { | |
const url = 'http://mathsoc.uwaterloo.ca/exambank/exams/' + item[0] + '/' + item[1]; | |
request(url, (err, response, body) => { | |
if (err || response.statusCode !== 200) | |
return callback(null); | |
const regexp = new RegExp("(http:\/\/mathsoc\.uwaterloo\.ca\/exambank\/exams.*?exam)", "g"); | |
while ((temp = regexp.exec(body)) !== null) { | |
console.log(temp[1]); | |
} | |
return callback(null); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment