#include "restaurants.hpp" #include "../network/network.hpp" #include "../htmlparser.hpp" #include void LunchRest::SuziesRestaurant::parse() { Request r; auto html = r.get(_url); if (html == "") return; clearMenus(); HtmlParser hparse(html); auto &root = hparse.getRoot(); auto days = root.find("//div[@class='uk-card-body item']"); for (auto &day : days) { auto daytext = nodeToText(day->find("./h2/text()")[0]); int cur_day = 0; switch (daytext[0]) { case 'P': if (daytext[1] != 'o') { cur_day = 4; } break; case "Ú"[0]: cur_day = 1; break; case 'S': cur_day = 2; break; case "Č"[0]: cur_day = 3; default: break; } bool working_on_meal = false; bool working_on_soup = false; Meal meal{}; for (auto &child : day->get_children()) { if (child->get_name() == "h3" && child->find("./text()").size() != 0) { auto meal_type = trim(nodeToText(child->find("./text()")[0])); meal = Meal(); working_on_meal = true; if (meal_type == "Polévka") { working_on_soup = true; meal.setSoup(); } else { meal.setDesc(meal_type); } } if (working_on_meal && child->get_name() == "div") { if (!working_on_soup) { auto price_elements = child->find("./div[contains(@class, 'price')]/text()"); if (price_elements.size() == 0) { goto end; } auto price = nodeToText(price_elements[0]); meal.setPrice(std::stoi(price)); auto namelen = child ->find("./div[contains(@class, " "'uk-width-expand')]/text()") .size(); std::string name = ""; if (namelen == 1) { name = trim(nodeToText(child->find( "./div[contains(@class, 'uk-width-expand')]/text()") [0])); } 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])); } meal.setName(name); } else { auto name = trim(nodeToText(child->find( "./div[contains(@class, 'uk-width-expand')]/text()") [0])); meal.setName(name); } menus[cur_day].addMeal(meal); end: working_on_meal = false; working_on_soup = false; } } menus[cur_day].setInvalidMenu(false); } }