~shreyasminocha/rice-dining-api

cce22595d195bc4846c5c6d41be33aecaa84ae28 — Shreyas Minocha 2 years ago 206171d
Include menu item tags
3 files changed, 20 insertions(+), 5 deletions(-)

A src/item-to-data.js
M src/meal-to-data.js
M src/scrape.js
A src/item-to-data.js => src/item-to-data.js +16 -0
@@ 0,0 1,16 @@
function itemToData(item) {
	const iconsDom = item.querySelectorAll('.icons');

	return {
		item: item.querySelector('.mitem').textContent,
		tags: Array.from(iconsDom).map(iconDomToTags),
	};
}

function iconDomToTags(iconDom) {
	return Array.from(iconDom.classList)
		.find((className) => !['icons', 'icon-only'].includes(className))
		.replace(/^icons-/, '');
}

export default itemToData;

M src/meal-to-data.js => src/meal-to-data.js +4 -2
@@ 1,9 1,11 @@
import itemToData from './item-to-data.js';

function mealToData(meal) {
	return {
		meal: meal.querySelector('.title').textContent,
		menu: Array
			.from(meal.querySelectorAll('.menu-items .mitem'))
			.map((mitem) => mitem.textContent),
			.from(meal.querySelectorAll('.menu-items tr td'))
			.map(itemToData),
	}
}


M src/scrape.js => src/scrape.js +0 -3
@@ 26,9 26,6 @@ async function getFullWeekMenu(servery) {
	return Array.from(mealsDom).map(mealToData);
}

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

export {
	getDailyMenu,
	getFullWeekMenu,