lunch-rest/restaurants/plac.cpp

51 lines
1.7 KiB
C++
Raw Normal View History

2020-09-16 09:20:27 +00:00
#include "restaurants.hpp"
#include "../network/network.hpp"
#include "../htmlparser.hpp"
void LunchRest::PlacRestaurant::parse() {
Request r;
auto html = r.get(_url);
if(html == "")
return;
clearMenus();
HtmlParser hparse(html);
auto &root = hparse.getRoot();
2021-02-09 22:23:37 +00:00
auto pizzas = root.find("//div[@class='mt-c cf']//div[@class='mt-i cf']");
if(pizzas.size() == 0)
return;
2021-02-11 17:39:39 +00:00
auto soups = pizzas[0]->find(".//div[@class='b b-text cf']");
2020-09-16 09:20:27 +00:00
2021-02-11 17:39:39 +00:00
int soup_price = std::stoi(nodeToText(soups[1]->find(".//strong/text()")[0]));
2020-09-16 09:20:27 +00:00
int cur_day = -1;
2021-02-11 17:39:39 +00:00
for(auto &soup : soups[0]->find(".//p/text()")) {
2020-09-16 09:20:27 +00:00
std::string soup_text = nodeToText(soup);
auto soup_day = soup_text.substr(0,2);
if(soup_day == "Po")
cur_day = 0;
if(cur_day < 0)
continue;
menus[cur_day].setInvalidMenu(false);
auto soupname = soup_text.substr(5);
while(std::isspace(soupname[0]))
soupname = soupname.substr(1);
menus[cur_day].addMeal(true, soupname, "", soup_price);
cur_day++;
if(cur_day > 4)
break;
}
for(unsigned long int i = 2; i < pizzas.size(); i++) {
2021-02-11 17:39:39 +00:00
auto content = pizzas[i]->find(".//div[@class='b b-text cf']");
2020-09-16 09:20:27 +00:00
auto name_candidates = content[0]->find(".//h3/text()");
std::string name = nodeToText(name_candidates[0]);
auto desc_candidates = content[0]->find(".//p//text()");
std::string desc = nodeToText(desc_candidates[0]);
auto price_candidates = content[1]->find(".//p/strong/text()");
int price = std::stoi(nodeToText(price_candidates[0]));
2021-02-11 17:39:39 +00:00
name = trim(name);
desc = trim(desc);
2020-09-16 09:20:27 +00:00
addPermanent(false, name, desc, price);
}
}