lunch-rest/parsers/padagali.cpp

30 lines
1.2 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() {
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("//div[@class='glf-mor-restaurant-menu-category']");
for(int i = 0; i < 5; i++) {
auto day = days[i];
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;
2020-09-15 14:05:16 +00:00
menus[menu_index].addMeal(soup, name, desc, 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
}
}