Added Má Hostina

This commit is contained in:
zv0n 2022-03-03 07:13:44 +01:00
parent e3ac4495f9
commit 40e2076cd3
5 changed files with 51 additions and 2 deletions

View File

@ -1,9 +1,9 @@
CXX ?= g++ 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 PREFIX ?= /usr/local/bin
LDFLAGS ?= -lcurl -lrestbed `pkg-config libxml-2.0 --libs` `pkg-config libxml++-3.0 --libs` 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 .PHONY: default
default: menuprint default: menuprint
@ -41,6 +41,8 @@ suzies.o: restaurants/suzies.cpp restaurants/restaurants.hpp network/network.hpp
$(CXX) $(CFLAGS) -c -o $@ $< $(CXX) $(CFLAGS) -c -o $@ $<
tao.o: restaurants/tao.cpp restaurants/restaurants.hpp network/network.hpp htmlparser.hpp tao.o: restaurants/tao.cpp restaurants/restaurants.hpp network/network.hpp htmlparser.hpp
$(CXX) $(CFLAGS) -c -o $@ $< $(CXX) $(CFLAGS) -c -o $@ $<
mahostina.o: restaurants/mahostina.cpp restaurants/restaurants.hpp network/network.hpp htmlparser.hpp
$(CXX) $(CFLAGS) -c -o $@ $<
clean: clean:
rm -Rf *.o menuprint rm -Rf *.o menuprint

View File

@ -110,6 +110,7 @@ int main(int /*UNUSED*/, char ** /*UNUSED*/, char **env) {
restaurants["zo"] = std::make_unique<LunchRest::ZoRestaurant>(); restaurants["zo"] = std::make_unique<LunchRest::ZoRestaurant>();
restaurants["suzies"] = std::make_unique<LunchRest::SuziesRestaurant>(); restaurants["suzies"] = std::make_unique<LunchRest::SuziesRestaurant>();
restaurants["tao"] = std::make_unique<LunchRest::TaoRestaurant>(); restaurants["tao"] = std::make_unique<LunchRest::TaoRestaurant>();
restaurants["mahostina"] = std::make_unique<LunchRest::MahostinaRestaurant>();
std::cout << "Initial parsing" << std::endl; std::cout << "Initial parsing" << std::endl;
for (auto &restaurant : restaurants) for (auto &restaurant : restaurants)
restaurant.second->parse(); restaurant.second->parse();

38
restaurants/mahostina.cpp Normal file
View File

@ -0,0 +1,38 @@
#include "restaurants.hpp"
#include "../network/network.hpp"
#include "../htmlparser.hpp"
#include <iostream>
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);
}

View File

@ -58,5 +58,11 @@ public:
virtual ~TaoRestaurant() = default; virtual ~TaoRestaurant() = default;
virtual void parse() override; 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 } // end of namespace LunchRest

View File

@ -40,12 +40,14 @@ void LunchRest::TaoRestaurant::parse() {
"tydenni-menu-div']"); "tydenni-menu-div']");
if (week_meals_html.empty()) { if (week_meals_html.empty()) {
std::cout << "No week meals :(" << std::endl; std::cout << "No week meals :(" << std::endl;
return;
} }
auto daily_meals_html = auto daily_meals_html =
root.find("//div[@class='ct-section-inner-wrap']/" root.find("//div[@class='ct-section-inner-wrap']/"
"div[@class='ct-div-block tydenni-menu-div']"); "div[@class='ct-div-block tydenni-menu-div']");
if (daily_meals_html.empty()) { if (daily_meals_html.empty()) {
std::cout << "No daily meals :(" << std::endl; std::cout << "No daily meals :(" << std::endl;
return;
} }
std::vector<Meal> week_meals{}; std::vector<Meal> week_meals{};