lunch-rest/restaurants/alcapone.cpp
2020-09-15 21:28:41 +02:00

52 lines
1.9 KiB
C++

#include "restaurants.hpp"
#include "../network/network.hpp"
#include "../htmlparser.hpp"
std::string removeAlergens(const std::string &name) {
int pos = name.length() - 1;
while(name[pos] == ',' || std::isdigit(name[pos]))
pos--;
return name.substr(0,pos);
}
void LunchRest::AlCaponeRestaurant::parse() {
clearMenus();
Request r;
auto html = r.get(_url);
if(html == "")
return;
HtmlParser hparse(html);
auto &root = hparse.getRoot();
auto rows = root.find("//table[@class='table table-responsive']/tbody/tr");
int cur_day = -1;
for(auto &row : rows) {
if(row->find("./td[@class='bg1']").size() != 0) {
std::string day = dynamic_cast<const xmlpp::ContentNode *>(row->find("./td[@class='bg1']/text()")[0])->get_content();
if(day.find("pondělí") != std::string::npos)
cur_day = 0;
else if(day.find("úterý") != std::string::npos)
cur_day = 1;
else if(day.find("středa") != std::string::npos)
cur_day = 2;
else if(day.find("čtvrtek") != std::string::npos)
cur_day = 3;
else if(day.find("pátek") != std::string::npos)
cur_day = 4;
menus[cur_day].setInvalidMenu(false);
continue;
}
if(cur_day < 0)
continue;
auto menu_info = row->find("./td/text()");
auto meal_data = row->find("./td/h3/text()");
std::string menu = dynamic_cast<const xmlpp::ContentNode *>(menu_info[0])->get_content();
std::string name = dynamic_cast<const xmlpp::ContentNode *>(meal_data[0])->get_content();
name = removeAlergens(name);
if(menu == "Polévka") {
menus[cur_day].addMeal(true, name, "", 0);
} else {
menus[cur_day].addMeal(false, name, "", std::stoi(dynamic_cast<const xmlpp::ContentNode *>(meal_data[1])->get_content()));
}
}
}