Padagali added span

This commit is contained in:
zvon 2021-08-03 20:57:05 +02:00
parent cbd45bfce8
commit f98670dee7

View File

@ -5,13 +5,17 @@
int dayToNum(const std::string &day) { int dayToNum(const std::string &day) {
if(day.find("POND") != std::string::npos) { if(day.find("POND") != std::string::npos) {
return 0; return 0;
} else if (day.find("ÚTER") != std::string::npos) { }
if (day.find("ÚTER") != std::string::npos) {
return 1; return 1;
} else if (day.find("STŘE") != std::string::npos) { }
if (day.find("STŘE") != std::string::npos) {
return 2; return 2;
} else if (day.find("ČTVR") != std::string::npos) { }
if (day.find("ČTVR") != std::string::npos) {
return 3; return 3;
} else if (day.find("PÁTE") != std::string::npos) { }
if (day.find("PÁTE") != std::string::npos) {
return 4; return 4;
} }
return -1; return -1;
@ -20,25 +24,27 @@ int dayToNum(const std::string &day) {
void LunchRest::PadagaliRestaurant::parse() { void LunchRest::PadagaliRestaurant::parse() {
Request r; Request r;
auto html = r.get(_url); auto html = r.get(_url);
if(html == "") if(html.empty()) {
return; return;
}
clearMenus(); clearMenus();
HtmlParser hparse(html); HtmlParser hparse(html);
auto &root = hparse.getRoot(); auto &root = hparse.getRoot();
auto days = root.find("//div[@class='glf-mor-restaurant-menu-category']"); auto days = root.find("//div[@class='glf-mor-restaurant-menu-category']");
auto menu_index = dayToNum(nodeToText(days[0]->find("./h3/text()")[0])); auto menu_index = dayToNum(nodeToText(days[0]->find("./h3/text()")[0]));
if(menu_index == -1) if(menu_index == -1) {
return; return;
}
auto max_div = 5 - menu_index; auto max_div = 5 - menu_index;
for(int i = 0; i < max_div; i++) { for(int i = 0; i < max_div; i++) {
auto day = days[i]; auto *day = days[i];
auto meals = day->find("./div"); auto meals = day->find("./div");
for(auto &meal : meals) { for(auto &meal : meals) {
auto info = meal->find("./div/div/div"); auto info = meal->find("./div/div/div");
std::string desc = nodeToText(info[1]->find("./text()")[0]); std::string desc = nodeToText(info[1]->find("./text()")[0]);
std::string name = nodeToText(info[0]->find("./h5/text()")[0]); std::string name = nodeToText(info[0]->find("./h5/text()")[0]);
int price = std::stoi(nodeToText(info[0]->find("./div/text()")[0])); int price = std::stoi(nodeToText(info[0]->find("./div/span/text()")[0]));
bool soup = name.find("Soup") == std::string::npos ? false : true; bool soup = name.find("Soup") != std::string::npos;
menus[menu_index].addMeal(soup, name, desc, price); menus[menu_index].addMeal(soup, name, desc, price);
menus[menu_index].setInvalidMenu(false); menus[menu_index].setInvalidMenu(false);
} }