diff --git a/main.cpp b/main.cpp index 5969a27..9779407 100644 --- a/main.cpp +++ b/main.cpp @@ -99,9 +99,9 @@ int main(int argc, char **argv, char **env) { restaurants["lightofindia"] = std::make_unique(); restaurants["ukarla"] = std::make_unique(); restaurants["alcapone"] = std::make_unique(); - restaurants["plac"] = std::make_unique(); +// restaurants["plac"] = std::make_unique(); restaurants["zo"] = std::make_unique(); - restaurants["suzzies"] = std::make_unique(); +// restaurants["suzzies"] = std::make_unique(); std::cout << "Initial parsing" << std::endl; for(auto &restaurant : restaurants) restaurant.second->parse(); diff --git a/restaurants/plac.cpp b/restaurants/plac.cpp index 3303150..c5c1176 100644 --- a/restaurants/plac.cpp +++ b/restaurants/plac.cpp @@ -20,7 +20,9 @@ void LunchRest::PlacRestaurant::parse() { clearMenus(); HtmlParser hparse(html); auto &root = hparse.getRoot(); - auto pizzas = root.find("//div[@class='section-inner']//div[@class='mt-i cf']"); + auto pizzas = root.find("//div[@class='mt-c cf']//div[@class='mt-i cf']"); + if(pizzas.size() == 0) + return; auto soups = pizzas[0]; int soup_price = std::stoi(nodeToText(pizzas[1]->find(".//strong/text()")[0])); diff --git a/restaurants/restaurants.cpp b/restaurants/restaurants.cpp index a0626df..c72f28d 100644 --- a/restaurants/restaurants.cpp +++ b/restaurants/restaurants.cpp @@ -3,3 +3,15 @@ std::string LunchRest::nodeToText(xmlpp::Node *node) { return dynamic_cast(node)->get_content(); } + +std::string LunchRest::trim(const std::string &input) { + const std::string whitespace = "\t\n\v\f\r "; + std::string ret = input; + ret.erase(0, ret.find_first_not_of(whitespace)); + ret.erase(ret.find_last_not_of(whitespace) + 1); + for(size_t i = 0; i < ret.length(); i++) { + if(ret[i] == '\n') + ret[i] = ' '; + } + return ret; +} diff --git a/restaurants/restaurants.hpp b/restaurants/restaurants.hpp index 273b421..99f6852 100644 --- a/restaurants/restaurants.hpp +++ b/restaurants/restaurants.hpp @@ -3,9 +3,10 @@ namespace LunchRest { std::string nodeToText(xmlpp::Node *node); +std::string trim(const std::string &input); class UDrevakaRestaurant : public Restaurant { public: - UDrevakaRestaurant() : Restaurant("https://www.udrevaka.cz/denni-menu/", "U Dřeváka") {} + UDrevakaRestaurant() : Restaurant("https://udrevaka.cz/denni-menu/", "U Dřeváka") {} virtual ~UDrevakaRestaurant() = default; virtual void parse() override; }; @@ -23,7 +24,7 @@ public: }; class UKarlaRestaurant : public Restaurant { public: - UKarlaRestaurant() : Restaurant("https://www.ukarlabrno.cz/denni-menu/", "U Karla") {} + UKarlaRestaurant() : Restaurant("https://ukarlabrno.cz/denni-menu/", "U Karla") {} virtual ~UKarlaRestaurant() = default; virtual void parse() override; }; diff --git a/restaurants/udrevaka.cpp b/restaurants/udrevaka.cpp index 430ae17..91ac086 100644 --- a/restaurants/udrevaka.cpp +++ b/restaurants/udrevaka.cpp @@ -14,10 +14,10 @@ void LunchRest::UDrevakaRestaurant::parse() { auto days = root.find("//li[@class='item-day']"); for(auto &day : days) { auto meals = day->find("./div[@class='row']"); - for(auto meal : meals) { + for(auto &meal : meals) { auto divs = meal->find(".//div/text()"); Meal meal_obj{}; - std::string name = nodeToText(divs[0]); + std::string name = trim(nodeToText(divs[0])); auto soup_pos = name.find("Polévka"); if(soup_pos != std::string::npos) { meal_obj.setSoup(); @@ -26,7 +26,7 @@ void LunchRest::UDrevakaRestaurant::parse() { meal_obj.setName(name.substr(3, name.find('(') - 4)); } if(divs.size() > 1) { - meal_obj.setPrice(std::stoi(nodeToText(divs[1]))); + meal_obj.setPrice(std::stoi(trim(nodeToText(divs[1])))); } menus[menu_index].addMeal(meal_obj); menus[menu_index].setInvalidMenu(false); diff --git a/restaurants/ukarla.cpp b/restaurants/ukarla.cpp index 0a54d10..d2ae6f4 100644 --- a/restaurants/ukarla.cpp +++ b/restaurants/ukarla.cpp @@ -19,7 +19,7 @@ void LunchRest::UKarlaRestaurant::parse() { for(auto &meal : meals) { auto soup = false; auto texts = meal->find("./div/text()"); - std::string name = nodeToText(texts[0]); + std::string name = trim(nodeToText(texts[0])); if(name[0] == 'P') { soup = true; name = name.substr(10); @@ -28,7 +28,7 @@ void LunchRest::UKarlaRestaurant::parse() { } int price = -1; if(texts.size() > 1) - price = std::stoi(nodeToText(texts[1])); + price = std::stoi(trim(nodeToText(texts[1]))); menus[menu_index].addMeal(soup, name, "", price); menus[menu_index].setInvalidMenu(false); }