lunch-rest/parsers/padagali.cpp

27 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::PadagaliParser::parse() {
menus.clear();
Request r;
auto html = r.get(_url);
HtmlParser hparse(html);
auto &root = hparse.getRoot();
auto days = root.find("//div[@class='glf-mor-restaurant-menu-category']");
for(int i = 0; i < 5; i++) {
auto day = days[i];
Menu m{};
auto meals = day->find("./div");
for(auto &meal : meals) {
auto info = meal->find("./div/div/div");
std::string desc = dynamic_cast<const xmlpp::ContentNode *>(info[1]->find("./text()")[0])->get_content();
std::string name = dynamic_cast<const xmlpp::ContentNode *>(info[0]->find("./h5/text()")[0])->get_content();
int price = std::stoi(dynamic_cast<const xmlpp::ContentNode *>(info[0]->find("./div/text()")[0])->get_content());
bool soup = name.find("Soup") == std::string::npos ? false : true;
m.addMeal(soup, name, desc, price);
}
menus.push_back(m);
}
}