Skip to content

Instantly share code, notes, and snippets.

@sentanos
Last active June 23, 2022 03:56
Show Gist options
  • Save sentanos/db9eac158a662a38a643d2ddf02acbb1 to your computer and use it in GitHub Desktop.
Save sentanos/db9eac158a662a38a643d2ddf02acbb1 to your computer and use it in GitHub Desktop.
Outputs a compiled list of all UW and Washington Community College course equivalencies
const axios = require("axios");
const cheerio = require("cheerio");
const fs = require("fs");
const { stringify } = require('csv-stringify/sync');
const OUTPUT_FILE = "./mappings.csv";
const MASTER_LIST_URL = "https://admit.washington.edu/apply/transfer/equivalency-guide";
const ROOT_URL = "https://admit.washington.edu";
const getColleges = async (url) => {
const html = (await axios.get(url)).data;
const $ = cheerio.load(html);
return $(".nav-stacked li a").map((_, e) => {
const $e = $(e);
return {
name: $e.text(),
url: ROOT_URL + $e.attr("href")
}
})
.toArray();
}
const getCourseMappings = async (college) => {
const name = college.name;
const url = college.url;
const html = (await axios.get(url)).data;
const $ = cheerio.load(html);
const courses = $("td.cccourse");
const uwequivs = $("td.uwequiv");
const uwreqs = $("td.uwreqs");
const effdate = $("td.effdate");
const mappings = [];
for (let i = 0; i < courses.length; i++) {
mappings.push({
college: name,
cc_course: $(courses[i]).text(),
uw_equiv: $(uwequivs[i]).text(),
uw_reqs: $(uwreqs[i]).text(),
eff_date: $(effdate[i]).text()
});
}
console.log("Completed " + name);
return mappings;
}
const getAllMappings = async () => {
const colleges = await getColleges(MASTER_LIST_URL);
console.log("Using college list:");
console.log(colleges);
const promises = colleges.map(getCourseMappings);
const results = await Promise.all(promises);
return results.flat();
}
const main = async () => {
const mappings = await getAllMappings();
fs.writeFileSync(OUTPUT_FILE, stringify(mappings, { header: true }));
}
main()
.catch((err) => {
console.error("Error running main: " + err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment