#include "restaurants.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::LightOfIndiaRestaurant::parse() { Request r; auto html = r.get(_url); if(html == "") return; clearMenus(); 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(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); menus[index].setInvalidMenu(false); } }