Ukrycie opcji wzywania kelnera
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const html = fs.readFileSync('menu.txt', 'utf8');
|
||||
|
||||
const items = [];
|
||||
const regexCategory = /<div class="rm-category">([\s\S]*?)<\/div>\s*<\/div>/g;
|
||||
const regexTitle = /class="restaurant-menu-category">([^<]+)<\/a>/;
|
||||
const regexPosition = /<div class="rmc-position" data-position="([^"]*)" data-category-id="([^"]*)" data-tag="([^"]*)">([\s\S]*?)<\/div>\s*<\/div>\s*<\/div>/g; // wait, the structure is a bit complex for simple regex.
|
||||
|
||||
// Let's use basic string splitting.
|
||||
|
||||
const cats = html.split('<div class="rm-category">');
|
||||
cats.shift(); // remove first empty
|
||||
|
||||
const result = [];
|
||||
|
||||
cats.forEach(catHtml => {
|
||||
const titleMatch = catHtml.match(/class="restaurant-menu-category">([^<]+)<\/a>/);
|
||||
const categoryName = titleMatch ? titleMatch[1].trim() : '';
|
||||
|
||||
const itemsMatches = catHtml.split('<div class="rmc-position"');
|
||||
itemsMatches.shift();
|
||||
|
||||
const categoryItems = [];
|
||||
itemsMatches.forEach(itemHtml => {
|
||||
const idMatch = itemHtml.match(/data-position="([^"]*)"/);
|
||||
const catIdMatch = itemHtml.match(/data-category-id="([^"]*)"/);
|
||||
const tagMatch = itemHtml.match(/data-tag="([^"]*)"/);
|
||||
const imgMatch = itemHtml.match(/<img[^>]+src="([^"]+)"/);
|
||||
const titleTextMatch = itemHtml.match(/<h4>([^<]+)/);
|
||||
const descMatch = itemHtml.match(/<span>([^<]*)<\/span>/);
|
||||
const priceMatch = itemHtml.match(/<div class="rmc-other">\s*<span>([^<]+)<\/span>/);
|
||||
|
||||
categoryItems.push({
|
||||
position: idMatch ? idMatch[1] : '',
|
||||
categoryId: catIdMatch ? catIdMatch[1] : '',
|
||||
tag: tagMatch ? tagMatch[1] : '',
|
||||
image: imgMatch ? imgMatch[1] : '',
|
||||
title: titleTextMatch ? titleTextMatch[1].trim() : '',
|
||||
description: descMatch ? descMatch[1].trim() : '',
|
||||
price: priceMatch ? priceMatch[1].trim() : ''
|
||||
});
|
||||
});
|
||||
|
||||
result.push({
|
||||
categoryName,
|
||||
items: categoryItems
|
||||
});
|
||||
});
|
||||
|
||||
fs.writeFileSync('public/menu.json', JSON.stringify(result, null, 2));
|
||||
console.log('Saved public/menu.json');
|
||||
Reference in New Issue
Block a user