lunch-rest/restaurants/ukarla.cpp

38 lines
1.1 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::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();
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()");
2020-09-16 15:04:19 +00:00
std::string name = nodeToText(texts[0]);
2020-09-14 22:55:03 +00:00
if(name[0] == 'P') {
soup = true;
name = name.substr(10);
} else {
name = name.substr(3);
2020-09-14 22:55:03 +00:00
}
int price = -1;
if(texts.size() > 1)
2020-09-16 15:04:19 +00:00
price = std::stoi(nodeToText(texts[1]));
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
}
}