lunch-rest/restaurants/padagali.cpp
2021-08-03 20:57:05 +02:00

54 lines
1.6 KiB
C++

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