lunch-rest/restaurants/udrevaka.cpp

37 lines
1.2 KiB
C++
Raw Normal View History

#include "restaurants.hpp"
2020-09-14 22:55:03 +00:00
#include "../network/network.hpp"
#include "../htmlparser.hpp"
void LunchRest::UDrevakaRestaurant::parse() {
2020-09-15 14:05:16 +00:00
int menu_index = 0;
2020-09-14 22:55:03 +00:00
Request r;
auto html = r.get(_url);
2020-09-15 14:05:16 +00:00
if(html == "")
return;
2020-09-15 21:04:16 +00:00
clearMenus();
2020-09-14 22:55:03 +00:00
HtmlParser hparse(html);
auto &root = hparse.getRoot();
auto days = root.find("//li[@class='item-day']");
for(auto &day : days) {
auto meals = day->find("./div[@class='row']");
for(auto meal : meals) {
auto divs = meal->find(".//div/text()");
Meal meal_obj{};
2020-09-16 15:04:19 +00:00
std::string name = nodeToText(divs[0]);
2020-09-14 22:55:03 +00:00
auto soup_pos = name.find("Polévka");
if(soup_pos != std::string::npos) {
meal_obj.setSoup();
meal_obj.setName(name.substr(10, name.find('(') - 11));
} else {
meal_obj.setName(name.substr(3, name.find('(') - 4));
}
if(divs.size() > 1) {
2020-09-16 15:04:19 +00:00
meal_obj.setPrice(std::stoi(nodeToText(divs[1])));
2020-09-14 22:55:03 +00:00
}
2020-09-15 14:05:16 +00:00
menus[menu_index].addMeal(meal_obj);
menus[menu_index].setInvalidMenu(false);
2020-09-14 22:55:03 +00:00
}
2020-09-15 14:05:16 +00:00
menu_index++;
2020-09-14 22:55:03 +00:00
}
}