lunch-rest/restaurants/mahostina.cpp

40 lines
1.2 KiB
C++

#include "functions.hpp"
#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);
}