~shreyasminocha/rice-dining-api

321c93df2de6b55a34a580194b89f5f1046e7f21 — Shreyas Minocha 2 years ago 4a75efd
Add full week menu scraping
1 files changed, 11 insertions(+), 2 deletions(-)

M src/scrape.js
M src/scrape.js => src/scrape.js +11 -2
@@ 8,10 8,19 @@ async function getDailyMenu(servery) {
	const res = await got(`https://web-api3.rice.edu/static/${servery}-menu-new.js`);
	const menuHtml = eval(res.body + `${camelcase(servery)}MenuTemplate()`); // eval bad
	const dom = new jsdom.JSDOM(pageify(menuHtml));
	const doc = dom.window.document;
	const mealsDom = doc.querySelectorAll('.inside-daily-menu .item:not(.legend)');
	const mealsDom = dom.window.document.querySelectorAll('.inside-daily-menu .item:not(.legend)');

	return Array.from(mealsDom).map(mealToData);
}

async function getFullWeekMenu(servery) {
	const res = await got(`https://web-api3.rice.edu/static/${servery}-menu-full-week-new.js`);
	const menuHtml = eval(res.body + `${camelcase(servery)}MenuFullWeekTemplate()`);
	const dom = new jsdom.JSDOM(pageify(menuHtml));
	const mealsDom = dom.window.document.querySelectorAll('.weekly-menu .item:not(.legend)');

	return Array.from(mealsDom).map(mealToData);
}

console.log(await getDailyMenu('seibel-servery'));
console.log(await getFullWeekMenu('seibel-servery'));