2020-09-15 15:25:27 +00:00
|
|
|
#include "restaurants.hpp"
|
2020-09-14 22:55:03 +00:00
|
|
|
#include "../network/network.hpp"
|
|
|
|
#include "../htmlparser.hpp"
|
|
|
|
|
2020-09-16 15:04:19 +00:00
|
|
|
int dayToNum(const std::string &day) {
|
|
|
|
if(day.find("POND") != std::string::npos) {
|
|
|
|
return 0;
|
2021-08-03 18:57:05 +00:00
|
|
|
}
|
|
|
|
if (day.find("ÚTER") != std::string::npos) {
|
2020-09-16 15:04:19 +00:00
|
|
|
return 1;
|
2021-08-03 18:57:05 +00:00
|
|
|
}
|
|
|
|
if (day.find("STŘE") != std::string::npos) {
|
2020-09-16 15:04:19 +00:00
|
|
|
return 2;
|
2021-08-03 18:57:05 +00:00
|
|
|
}
|
|
|
|
if (day.find("ČTVR") != std::string::npos) {
|
2020-09-16 15:04:19 +00:00
|
|
|
return 3;
|
2021-08-03 18:57:05 +00:00
|
|
|
}
|
|
|
|
if (day.find("PÁTE") != std::string::npos) {
|
2020-09-16 15:04:19 +00:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:25:27 +00:00
|
|
|
void LunchRest::PadagaliRestaurant::parse() {
|
2020-09-14 22:55:03 +00:00
|
|
|
Request r;
|
|
|
|
auto html = r.get(_url);
|
2021-08-03 18:57:05 +00:00
|
|
|
if(html.empty()) {
|
2020-09-15 14:05:16 +00:00
|
|
|
return;
|
2021-08-03 18:57:05 +00:00
|
|
|
}
|
2020-09-15 21:04:16 +00:00
|
|
|
clearMenus();
|
2020-09-14 22:55:03 +00:00
|
|
|
HtmlParser hparse(html);
|
|
|
|
auto &root = hparse.getRoot();
|
|
|
|
auto days = root.find("//div[@class='glf-mor-restaurant-menu-category']");
|
2020-09-16 15:04:19 +00:00
|
|
|
auto menu_index = dayToNum(nodeToText(days[0]->find("./h3/text()")[0]));
|
2021-08-03 18:57:05 +00:00
|
|
|
if(menu_index == -1) {
|
2020-09-16 15:04:19 +00:00
|
|
|
return;
|
2021-08-03 18:57:05 +00:00
|
|
|
}
|
2020-09-16 15:09:17 +00:00
|
|
|
auto max_div = 5 - menu_index;
|
|
|
|
for(int i = 0; i < max_div; i++) {
|
2021-08-03 18:57:05 +00:00
|
|
|
auto *day = days[i];
|
2020-09-14 22:55:03 +00:00
|
|
|
auto meals = day->find("./div");
|
|
|
|
for(auto &meal : meals) {
|
|
|
|
auto info = meal->find("./div/div/div");
|
2020-09-16 15:04:19 +00:00
|
|
|
std::string desc = nodeToText(info[1]->find("./text()")[0]);
|
|
|
|
std::string name = nodeToText(info[0]->find("./h5/text()")[0]);
|
2021-08-03 18:57:05 +00:00
|
|
|
int price = std::stoi(nodeToText(info[0]->find("./div/span/text()")[0]));
|
|
|
|
bool soup = name.find("Soup") != std::string::npos;
|
2020-09-15 14:05:16 +00:00
|
|
|
menus[menu_index].addMeal(soup, name, desc, price);
|
|
|
|
menus[menu_index].setInvalidMenu(false);
|
2020-09-14 22:55:03 +00:00
|
|
|
}
|
2020-09-15 14:05:16 +00:00
|
|
|
menu_index++;
|
2020-09-14 22:55:03 +00:00
|
|
|
}
|
|
|
|
}
|