lunch-rest/restaurants/alcapone.cpp

56 lines
1.9 KiB
C++
Raw Normal View History

#include "restaurants.hpp"
2020-09-15 14:05:16 +00:00
#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() {
2020-09-15 14:05:16 +00:00
Request r;
auto html = r.get(_url);
if(html == "")
return;
2020-09-15 21:04:16 +00:00
clearMenus();
2020-09-15 14:05:16 +00:00
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) {
2020-09-16 15:04:19 +00:00
std::string day = nodeToText(row->find("./td[@class='bg1']/text()")[0]);
2020-09-15 14:05:16 +00:00
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;
2020-09-20 14:43:13 +00:00
else if(day.find("sobota") != std::string::npos)
cur_day = 5;
else if(day.find("neděle") != std::string::npos)
cur_day = 6;
2020-09-15 14:05:16 +00:00
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()");
2020-09-16 15:04:19 +00:00
std::string menu = nodeToText(menu_info[0]);
std::string name = nodeToText(meal_data[0]);
2020-09-15 14:05:16 +00:00
name = removeAlergens(name);
if(menu == "Polévka") {
menus[cur_day].addMeal(true, name, "", 0);
} else {
2020-09-16 15:04:19 +00:00
menus[cur_day].addMeal(false, name, "", std::stoi(nodeToText(meal_data[1])));
2020-09-15 14:05:16 +00:00
}
}
}