Remove COUT and formatting

This commit is contained in:
zv0n 2022-02-24 16:46:21 +01:00
parent 4d7586168e
commit a635d7673a

View File

@ -12,76 +12,84 @@ int weekDay(const std::string &date_str) {
void LunchRest::SuziesRestaurant::parse() { void LunchRest::SuziesRestaurant::parse() {
Request r; Request r;
auto html = r.get(_url); auto html = r.get(_url);
if(html == "") if (html == "")
return; return;
clearMenus(); clearMenus();
HtmlParser hparse(html); HtmlParser hparse(html);
auto &root = hparse.getRoot(); auto &root = hparse.getRoot();
auto days = root.find("//div[@class='uk-card-body item']"); auto days = root.find("//div[@class='uk-card-body item']");
std::cout << "IMMA TRY" << std::endl; for (auto &day : days) {
for(auto &day : days) {
auto daytext = nodeToText(day->find("./h2/text()")[0]); auto daytext = nodeToText(day->find("./h2/text()")[0]);
int cur_day = 0; int cur_day = 0;
switch(daytext[0]) { switch (daytext[0]) {
case 'P': case 'P':
if(daytext[1] != 'o') { if (daytext[1] != 'o') {
cur_day = 4; cur_day = 4;
} }
break; break;
case "Ú"[0]: case "Ú"[0]:
cur_day = 1; cur_day = 1;
break; break;
case 'S': case 'S':
cur_day = 2; cur_day = 2;
break; break;
case "Č"[0]: case "Č"[0]:
cur_day = 3; cur_day = 3;
default: default:
break; break;
} }
std::cout << "DAY: " << cur_day << std::endl;
bool working_on_meal = false; bool working_on_meal = false;
bool working_on_soup = false; bool working_on_soup = false;
Meal meal{}; Meal meal{};
for(auto &child : day->get_children()) { for (auto &child : day->get_children()) {
if(child->get_name() == "h3" && child->find("./text()").size() != 0) { if (child->get_name() == "h3" &&
std::cout << "MEAL" << std::endl; child->find("./text()").size() != 0) {
auto meal_type = trim(nodeToText(child->find("./text()")[0])); auto meal_type = trim(nodeToText(child->find("./text()")[0]));
std::cout << meal_type << std::endl;
meal = Meal(); meal = Meal();
working_on_meal = true; working_on_meal = true;
if(meal_type == "Polévka") { if (meal_type == "Polévka") {
working_on_soup = true; working_on_soup = true;
meal.setSoup(); meal.setSoup();
} else { } else {
meal.setDesc(meal_type); meal.setDesc(meal_type);
} }
} }
if(working_on_meal && child->get_name() == "div") { if (working_on_meal && child->get_name() == "div") {
if(!working_on_soup) { if (!working_on_soup) {
auto price_elements = child->find("./div[contains(@class, 'price')]/text()"); auto price_elements =
if(price_elements.size() == 0) { child->find("./div[contains(@class, 'price')]/text()");
if (price_elements.size() == 0) {
goto end; goto end;
} }
auto price = nodeToText(price_elements[0]); auto price = nodeToText(price_elements[0]);
std::cout << "PRICE: " << price << std::endl;
meal.setPrice(std::stoi(price)); meal.setPrice(std::stoi(price));
auto namelen = child->find("./div[contains(@class, 'uk-width-expand')]/text()").size(); auto namelen = child
->find("./div[contains(@class, "
"'uk-width-expand')]/text()")
.size();
std::string name = ""; std::string name = "";
if(namelen == 1) { if (namelen == 1) {
name = trim(nodeToText(child->find("./div[contains(@class, 'uk-width-expand')]/text()")[0])); name = trim(nodeToText(child->find(
"./div[contains(@class, 'uk-width-expand')]/text()")
[0]));
} else { } else {
name = trim(nodeToText(child->find("./div[contains(@class, 'uk-width-expand')]/span/text()")[0])) + " " + trim(nodeToText(child->find("./div[contains(@class, 'uk-width-expand')]/text()")[1])); name = trim(nodeToText(child->find(
"./div[contains(@class, "
"'uk-width-expand')]/span/text()")[0])) +
" " +
trim(nodeToText(child->find(
"./div[contains(@class, "
"'uk-width-expand')]/text()")[1]));
} }
std::cout << name << std::endl;
meal.setName(name); meal.setName(name);
} else { } else {
auto name = trim(nodeToText(child->find("./div[contains(@class, 'uk-width-expand')]/text()")[0])); auto name = trim(nodeToText(child->find(
std::cout << name << std::endl; "./div[contains(@class, 'uk-width-expand')]/text()")
[0]));
meal.setName(name); meal.setName(name);
} }
menus[cur_day].addMeal(meal); menus[cur_day].addMeal(meal);
end: end:
working_on_meal = false; working_on_meal = false;
working_on_soup = false; working_on_soup = false;
} }