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;
|
|
|
|
} else if (day.find("ÚTER") != std::string::npos) {
|
|
|
|
return 1;
|
|
|
|
} else if (day.find("STŘE") != std::string::npos) {
|
|
|
|
return 2;
|
|
|
|
} else if (day.find("ČTVR") != std::string::npos) {
|
|
|
|
return 3;
|
|
|
|
} else if (day.find("PÁTE") != std::string::npos) {
|
|
|
|
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);
|
2020-09-15 14:05:16 +00:00
|
|
|
if(html == "")
|
|
|
|
return;
|
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]));
|
|
|
|
if(menu_index == -1)
|
|
|
|
return;
|
|
|
|
for(int i = 0; i < 5-menu_index; i++) {
|
2020-09-14 22:55:03 +00:00
|
|
|
auto day = days[i];
|
|
|
|
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]);
|
|
|
|
int price = std::stoi(nodeToText(info[0]->find("./div/text()")[0]));
|
2020-09-14 22:55:03 +00:00
|
|
|
bool soup = name.find("Soup") == std::string::npos ? false : true;
|
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
|
|
|
}
|
|
|
|
}
|