lunch-rest/parsers/ukarla.cpp

36 lines
1.1 KiB
C++
Raw Normal View History

2020-09-14 22:55:03 +00:00
#include "parsers.hpp"
#include "../network/network.hpp"
#include "../htmlparser.hpp"
void LunchRest::UKarlaParser::parse() {
2020-09-15 14:05:16 +00:00
clearMenus();
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-14 22:55:03 +00:00
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()");
std::string name = dynamic_cast<const xmlpp::ContentNode *>(texts[0])->get_content();
if(name[0] == 'P') {
soup = true;
name = name.substr(10);
}
int price = -1;
if(texts.size() > 1)
price = std::stoi(dynamic_cast<const xmlpp::ContentNode *>(texts[1])->get_content());
2020-09-15 14:05:16 +00:00
menus[menu_index].addMeal(soup, name, "", price);
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
}
}