2020-09-15 15:25:27 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:25:27 +00:00
|
|
|
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) {
|
|
|
|
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);
|
2020-09-15 14:05:16 +00:00
|
|
|
menus[index].setInvalidMenu(false);
|
2020-09-14 22:55:03 +00:00
|
|
|
}
|
|
|
|
}
|