Forgot some files

This commit is contained in:
zv0n 2020-09-16 11:20:27 +02:00
parent 2c46f2d64a
commit 0fbba2c010
2 changed files with 63 additions and 0 deletions

58
restaurants/plac.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "restaurants.hpp"
#include "../network/network.hpp"
#include "../htmlparser.hpp"
void trim(std::string &str) {
int start = 0;
int end = str.length() - 1;
while(std::isspace(str[start]))
start++;
while(std::isspace(str[end]))
end--;
str = str.substr(start, end - start);
}
void LunchRest::PlacRestaurant::parse() {
Request r;
auto html = r.get(_url);
if(html == "")
return;
clearMenus();
HtmlParser hparse(html);
auto &root = hparse.getRoot();
auto pizzas = root.find("//div[@class='section-inner']//div[@class='mt-i cf']");
auto soups = pizzas[0];
int soup_price = std::stoi(nodeToText(pizzas[1]->find(".//strong/text()")[0]));
int cur_day = -1;
for(auto &soup : soups->find(".//text()")) {
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++) {
auto content = pizzas[i]->find(".//div[@class='b-c b-text-c b-s b-s-t60 b-s-b60 cf']");
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]));
trim(name);
trim(desc);
addPermanent(false, name, desc, price);
}
}

View File

@ -0,0 +1,5 @@
#include "restaurants.hpp"
std::string LunchRest::nodeToText(xmlpp::Node *node) {
return dynamic_cast<const xmlpp::ContentNode *>(node)->get_content();
}