~shreyasminocha/rice-dining-api

a6950eadf70cd1576ed3190fe45b836f1ad0b7c0 — Shreyas Minocha 2 years ago 321c93d
Clean scraping helper
1 files changed, 12 insertions(+), 3 deletions(-)

M src/scrape.js
M src/scrape.js => src/scrape.js +12 -3
@@ 1,11 1,15 @@
import got from 'got';
import jsdom from 'jsdom';
import camelcase from 'camelcase';
import mealToData from './meal-to-data.js';
import pageify from './pageify.js';
import mealToData from './meal-to-data.js';

const api = got.extend({
	prefixUrl: 'https://web-api3.rice.edu',
});

async function getDailyMenu(servery) {
	const res = await got(`https://web-api3.rice.edu/static/${servery}-menu-new.js`);
	const res = await api.get(`static/${servery}-menu-new.js`);
	const menuHtml = eval(res.body + `${camelcase(servery)}MenuTemplate()`); // eval bad
	const dom = new jsdom.JSDOM(pageify(menuHtml));
	const mealsDom = dom.window.document.querySelectorAll('.inside-daily-menu .item:not(.legend)');


@@ 14,7 18,7 @@ async function getDailyMenu(servery) {
}

async function getFullWeekMenu(servery) {
	const res = await got(`https://web-api3.rice.edu/static/${servery}-menu-full-week-new.js`);
	const res = await api.get(`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)');


@@ 24,3 28,8 @@ async function getFullWeekMenu(servery) {

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

export {
	getDailyMenu,
	getFullWeekMenu,
};