#!/usr/bin/env node const cheerio = require("cheerio"); const fetch = require("node-fetch"); let query; if (process.argv.length == 2) { query = function(obj) {return true;}; } else if (process.argv.length == 3) { const s = process.argv[2]; query = function(obj) {with (obj) return eval(s);}; } else { console.log("Usage: ./filter.js 'period == 4 && slot[0] != \"D\"'"); process.exit(1); } function parseRow(row) { if (row.length != 6) return null; return { period: row[0], slot: row[1], code: row[2], year: row[3], ects: row[4], name: row[5], }; } function handle(html) { const $ = cheerio.load(html); let trs = []; $("tbody").last().children("tr").each((_, e) => trs.push($(e).children("td").map((_, td) => $(td).text()).get()) ); trs = trs.map(r => parseRow(r)).filter(obj => obj != null); trs.forEach(obj => { if (query(obj)) console.log(JSON.stringify(obj)); }); } fetch("http://www.cs.uu.nl/education/") .then(res => res.text()) .then(body => handle(body)) .catch(err => console.error(err));