diff --git a/restaurants/plac.cpp b/restaurants/plac.cpp new file mode 100644 index 0000000..3303150 --- /dev/null +++ b/restaurants/plac.cpp @@ -0,0 +1,58 @@ +#include "restaurants.hpp" +#include "../network/network.hpp" +#include "../htmlparser.hpp" + +void trim(std::string &str) { + int start = 0; + int end = str.length() - 1; + while(std::isspace(str[start])) + start++; + while(std::isspace(str[end])) + end--; + str = str.substr(start, end - start); +} + +void LunchRest::PlacRestaurant::parse() { + Request r; + auto html = r.get(_url); + if(html == "") + return; + clearMenus(); + HtmlParser hparse(html); + auto &root = hparse.getRoot(); + auto pizzas = root.find("//div[@class='section-inner']//div[@class='mt-i cf']"); + auto soups = pizzas[0]; + + int soup_price = std::stoi(nodeToText(pizzas[1]->find(".//strong/text()")[0])); + + int cur_day = -1; + for(auto &soup : soups->find(".//text()")) { + std::string soup_text = nodeToText(soup); + auto soup_day = soup_text.substr(0,2); + if(soup_day == "Po") + cur_day = 0; + if(cur_day < 0) + continue; + menus[cur_day].setInvalidMenu(false); + auto soupname = soup_text.substr(5); + while(std::isspace(soupname[0])) + soupname = soupname.substr(1); + menus[cur_day].addMeal(true, soupname, "", soup_price); + cur_day++; + if(cur_day > 4) + break; + } + + for(unsigned long int i = 2; i < pizzas.size(); i++) { + auto content = pizzas[i]->find(".//div[@class='b-c b-text-c b-s b-s-t60 b-s-b60 cf']"); + auto name_candidates = content[0]->find(".//h3/text()"); + std::string name = nodeToText(name_candidates[0]); + auto desc_candidates = content[0]->find(".//p//text()"); + std::string desc = nodeToText(desc_candidates[0]); + auto price_candidates = content[1]->find(".//p/strong/text()"); + int price = std::stoi(nodeToText(price_candidates[0])); + trim(name); + trim(desc); + addPermanent(false, name, desc, price); + } +} diff --git a/restaurants/restaurants.cpp b/restaurants/restaurants.cpp new file mode 100644 index 0000000..a0626df --- /dev/null +++ b/restaurants/restaurants.cpp @@ -0,0 +1,5 @@ +#include "restaurants.hpp" + +std::string LunchRest::nodeToText(xmlpp::Node *node) { + return dynamic_cast(node)->get_content(); +}