Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanlimanto/e753a0a00e515fa8f712b13dd6c9ae44 to your computer and use it in GitHub Desktop.
Save evanlimanto/e753a0a00e515fa8f712b13dd6c9ae44 to your computer and use it in GitHub Desktop.
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