lunch-rest/restaurants/ukarla.cpp

50 lines
1.6 KiB
C++
Raw Permalink Normal View History

2022-03-03 07:49:58 +00:00
#include "functions.hpp"
#include "restaurants.hpp"
2020-09-14 22:55:03 +00:00
#include "../network/network.hpp"
#include "../htmlparser.hpp"
void LunchRest::UKarlaRestaurant::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();
2022-09-24 21:13:42 +00:00
try {
HtmlParser hparse(html);
auto &root = hparse.getRoot();
auto days = root.find("//li[@class='item-day']");
int validdays = 0;
for(auto &day : days) {
validdays++;
auto meals = day->find("./div[@class='row']");
for(auto &meal : meals) {
auto soup = false;
auto texts = meal->find("./div/text()");
if(texts.empty()) {
menus[menu_index].addMeal(false, parseError, parseInfo, 0);
continue;
}
std::string name = trim(nodeToText(texts[0]));
if(name[0] == 'P') {
soup = true;
name = name.substr(10);
} else {
name = name.substr(3);
}
int price = -1;
if(texts.size() > 1)
price = std::stoi(trim(nodeToText(texts[1])));
menus[menu_index].addMeal(soup, name, "", price);
menus[menu_index].setInvalidMenu(false);
2020-09-14 22:55:03 +00:00
}
2022-09-24 21:13:42 +00:00
menu_index++;
}
} catch (std::exception &/*UNUSED*/) {
clearMenus();
for(int i = 0; i < menus.size(); i++) {
menus[i].addMeal(false, parseError, parseInfo, 0);
2020-09-14 22:55:03 +00:00
}
}
}