2020-09-20 14:27:49 +00:00
|
|
|
#include "restaurants.hpp"
|
|
|
|
#include "../network/network.hpp"
|
2021-02-11 18:19:39 +00:00
|
|
|
#include "../htmlparser.hpp"
|
2020-09-20 14:27:49 +00:00
|
|
|
|
|
|
|
int weekDay(const std::string &date_str) {
|
|
|
|
struct tm date_tm;
|
|
|
|
strptime(date_str.c_str(), "%Y-%m-%d %H:%M:%S", &date_tm);
|
2020-09-20 14:31:24 +00:00
|
|
|
return (date_tm.tm_wday + 6) % 7;
|
2020-09-20 14:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LunchRest::SuzziesRestaurant::parse() {
|
|
|
|
Request r;
|
2021-02-11 18:19:39 +00:00
|
|
|
auto html = r.get(_url);
|
|
|
|
if(html == "")
|
2020-09-20 14:27:49 +00:00
|
|
|
return;
|
|
|
|
clearMenus();
|
2021-02-11 18:19:39 +00:00
|
|
|
HtmlParser hparse(html);
|
|
|
|
auto &root = hparse.getRoot();
|
|
|
|
auto days = root.find("//div[@class='day']");
|
|
|
|
for(auto &day : days) {
|
|
|
|
auto *daynum = xmlGetProp(days[0]->cobj(), (xmlChar*)"data-day");
|
|
|
|
int cur_day = 0;
|
|
|
|
switch(daynum[0]) {
|
|
|
|
case '2':
|
|
|
|
cur_day = 1;
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
cur_day = 2;
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
cur_day = 3;
|
|
|
|
break;
|
|
|
|
case '5':
|
|
|
|
cur_day = 4;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for(auto &meal : day->find(".//div[@class='item']")) {
|
|
|
|
Meal meal_obj{};
|
|
|
|
auto type = trim(nodeToText(meal->find(".//h6/text()")[0]));
|
|
|
|
auto name_nodes = meal->find(".//div[@class='title']/text()");
|
|
|
|
auto text_nodes = meal->find(".//div[@class='text']/text()");
|
|
|
|
auto price_nodes = meal->find(".//div[@class='price']/text()");
|
|
|
|
if(price_nodes.size() > 0) {
|
|
|
|
// not soup
|
|
|
|
auto name = type;
|
|
|
|
if(name_nodes.size() > 0)
|
|
|
|
name += " - " + trim(nodeToText(name_nodes[0]));
|
|
|
|
meal_obj.setName(name);
|
|
|
|
if(text_nodes.size() > 0)
|
|
|
|
meal_obj.setDesc(trim(nodeToText(text_nodes[0])));
|
|
|
|
meal_obj.setPrice(std::stoi(trim(nodeToText(price_nodes[0]))));
|
|
|
|
} else {
|
|
|
|
meal_obj.setName(trim(nodeToText(name_nodes[0])));
|
|
|
|
meal_obj.setSoup();
|
2020-09-20 14:27:49 +00:00
|
|
|
}
|
2021-02-11 18:19:39 +00:00
|
|
|
menus[cur_day].addMeal(meal_obj);
|
2020-09-20 14:27:49 +00:00
|
|
|
}
|
2021-02-11 18:19:39 +00:00
|
|
|
menus[cur_day].setInvalidMenu(false);
|
2020-09-20 14:27:49 +00:00
|
|
|
}
|
|
|
|
}
|