lunch-rest/restaurants/lightofindia.cpp

45 lines
1.4 KiB
C++
Raw Normal View History

#include "restaurants.hpp"
2020-09-14 22:55:03 +00:00
#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::LightOfIndiaRestaurant::parse() {
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 container = root.find("//div[@id='content_container']")[0];
auto texts = container->find(".//td/text()");
int index = -1;
for(auto text : texts) {
2020-09-16 15:04:19 +00:00
std::string text_text = nodeToText(text);
2020-09-14 22:55:03 +00:00
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);
2020-09-15 14:05:16 +00:00
menus[index].setInvalidMenu(false);
2020-09-14 22:55:03 +00:00
}
}