diff --git a/Makefile b/Makefile index 3a3e548..c992d27 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ CXX ?= g++ -CFLAGS ?= -O2 -Wall -Wextra `pkg-config libxml-2.0 --cflags` `pkg-config libxml++-3.0 --cflags` -g +CFLAGS ?= -O2 -Wall -Wextra `pkg-config libxml-2.0 --cflags` `pkg-config libxml++-3.0 --cflags` PREFIX ?= /usr/local/bin LDFLAGS ?= -lcurl -lrestbed `pkg-config libxml-2.0 --libs` `pkg-config libxml++-3.0 --libs` -PARSERS = udrevaka.o padagali.o lightofindia.o ukarla.o alcapone.o plac.o zo.o suzies.o tao.o +PARSERS = udrevaka.o padagali.o lightofindia.o ukarla.o alcapone.o plac.o zo.o suzies.o tao.o mahostina.o .PHONY: default default: menuprint @@ -41,6 +41,8 @@ suzies.o: restaurants/suzies.cpp restaurants/restaurants.hpp network/network.hpp $(CXX) $(CFLAGS) -c -o $@ $< tao.o: restaurants/tao.cpp restaurants/restaurants.hpp network/network.hpp htmlparser.hpp $(CXX) $(CFLAGS) -c -o $@ $< +mahostina.o: restaurants/mahostina.cpp restaurants/restaurants.hpp network/network.hpp htmlparser.hpp + $(CXX) $(CFLAGS) -c -o $@ $< clean: rm -Rf *.o menuprint diff --git a/main.cpp b/main.cpp index 97dc28d..79429d3 100644 --- a/main.cpp +++ b/main.cpp @@ -110,6 +110,7 @@ int main(int /*UNUSED*/, char ** /*UNUSED*/, char **env) { restaurants["zo"] = std::make_unique(); restaurants["suzies"] = std::make_unique(); restaurants["tao"] = std::make_unique(); + restaurants["mahostina"] = std::make_unique(); std::cout << "Initial parsing" << std::endl; for (auto &restaurant : restaurants) restaurant.second->parse(); diff --git a/restaurants/mahostina.cpp b/restaurants/mahostina.cpp new file mode 100644 index 0000000..10f5b5a --- /dev/null +++ b/restaurants/mahostina.cpp @@ -0,0 +1,38 @@ +#include "restaurants.hpp" +#include "../network/network.hpp" +#include "../htmlparser.hpp" +#include + +void LunchRest::MahostinaRestaurant::parse() { + Request r; + auto html = r.get(_url); + if (html == "") + return; + clearMenus(); + HtmlParser hparse(html); + auto &root = hparse.getRoot(); + auto today_lists = root.find( + "//div[@id='dnesnibasta-section']//ul[@data-rte-list='default']"); + if (today_lists.empty()) { + std::cout << "No meals :(" << std::endl; + return; + } + + time_t t = time(nullptr); + tm *timePtr = localtime(&t); + auto day = (timePtr->tm_wday + 6) % 7; + + for (auto &meal : today_lists[0]->find("./li/p/text()")) { + auto text = nodeToText(meal); + auto price_end = text.find(",-"); + auto price_start = price_end - 1; + while (text[price_start] >= '0' && text[price_start] <= '9') { + price_start -= 1; + } + price_start += 1; + menus[day].addMeal( + false, text.substr(0, price_start - 1), "", + std::stoi(text.substr(price_start, price_end - price_start))); + } + menus[day].setInvalidMenu(false); +} diff --git a/restaurants/restaurants.hpp b/restaurants/restaurants.hpp index ddf8504..e4b74e2 100644 --- a/restaurants/restaurants.hpp +++ b/restaurants/restaurants.hpp @@ -58,5 +58,11 @@ public: virtual ~TaoRestaurant() = default; virtual void parse() override; }; +class MahostinaRestaurant : public Restaurant { +public: + MahostinaRestaurant() : Restaurant("https://www.mahostina.cz/", "Má Hostina") {} + virtual ~MahostinaRestaurant() = default; + virtual void parse() override; +}; } // end of namespace LunchRest diff --git a/restaurants/tao.cpp b/restaurants/tao.cpp index 9a20eb7..d096a28 100644 --- a/restaurants/tao.cpp +++ b/restaurants/tao.cpp @@ -40,12 +40,14 @@ void LunchRest::TaoRestaurant::parse() { "tydenni-menu-div']"); if (week_meals_html.empty()) { std::cout << "No week meals :(" << std::endl; + return; } auto daily_meals_html = root.find("//div[@class='ct-section-inner-wrap']/" "div[@class='ct-div-block tydenni-menu-div']"); if (daily_meals_html.empty()) { std::cout << "No daily meals :(" << std::endl; + return; } std::vector week_meals{};