lunch-rest/parsers/lightofindia.cpp
2020-09-15 00:55:03 +02:00

44 lines
1.4 KiB
C++

#include "parsers.hpp"
#include "../network/network.hpp"
#include "../htmlparser.hpp"
bool isWhiteSpaceOnly(const std::string &text) {
if(text == "")
return true;
for(auto &x : text) {
if(!std::isspace(x))
return false;
}
return true;
}
void LunchRest::LightOfIndiaParser::parse() {
menus.clear();
menus.resize(5);
Request r;
auto html = r.get(_url);
HtmlParser hparse(html);
auto &root = hparse.getRoot();
auto container = root.find("//div[@id='content_container']")[0];
auto texts = container->find(".//td/text()");
int index = -1;
for(auto text : texts) {
Menu m{};
std::string text_text = dynamic_cast<const xmlpp::ContentNode *>(text)->get_content();
if(isWhiteSpaceOnly(text_text) || text_text.find("Week") != std::string::npos)
continue;
if(text_text[0] == '1')
index++;
auto end = text_text.find(')');
if(end == std::string::npos)
continue;
auto possible_end = text_text.find('g', end);
if(possible_end != std::string::npos)
end = possible_end;
std::string name = text_text.substr(4, end - 3);
int price = std::stoi(text_text.substr(end+1));
bool soup = name.find("soup") == std::string::npos ? false : true;
menus[index].addMeal(soup, name, "", price);
}
}