Add refresh
This commit is contained in:
parent
09b314c5b0
commit
5b67c65a03
12
main.cpp
12
main.cpp
@ -11,6 +11,13 @@
|
||||
std::vector<std::string> days = {"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"};
|
||||
std::vector<std::unique_ptr<LunchRest::Restaurant>> restaurants;
|
||||
|
||||
void refresh( const std::shared_ptr< restbed::Session > session ) {
|
||||
for(auto &x : restaurants)
|
||||
x->parse();
|
||||
std::string response = "Refreshed menus!";
|
||||
session->close(restbed::OK, response, { { "Content-Length", std::to_string(response.length()) }, { "Access-Control-Allow-Origin", "*" } });
|
||||
}
|
||||
|
||||
void get_all( const std::shared_ptr< restbed::Session > session ) {
|
||||
std::stringstream ss{};
|
||||
bool atleastonerest = false;
|
||||
@ -108,6 +115,11 @@ int main() {
|
||||
getserv->set_method_handler( "GET", get );
|
||||
service.publish(getserv);
|
||||
|
||||
auto refreshserv = std::make_shared< restbed::Resource >();
|
||||
refreshserv->set_path("/refresh");
|
||||
refreshserv->set_method_handler( "GET", refresh );
|
||||
service.publish(refreshserv);
|
||||
|
||||
auto ssl_settings = std::make_shared<restbed::SSLSettings>();
|
||||
ssl_settings->set_http_disabled(true);
|
||||
ssl_settings->set_private_key(restbed::Uri("file:///home/zvon/data/programming/lunch-rest/example.key"));
|
||||
|
@ -10,11 +10,11 @@ std::string removeAlergens(const std::string &name) {
|
||||
}
|
||||
|
||||
void LunchRest::AlCaponeRestaurant::parse() {
|
||||
clearMenus();
|
||||
Request r;
|
||||
auto html = r.get(_url);
|
||||
if(html == "")
|
||||
return;
|
||||
clearMenus();
|
||||
HtmlParser hparse(html);
|
||||
auto &root = hparse.getRoot();
|
||||
auto rows = root.find("//table[@class='table table-responsive']/tbody/tr");
|
||||
|
@ -13,11 +13,11 @@ bool isWhiteSpaceOnly(const std::string &text) {
|
||||
}
|
||||
|
||||
void LunchRest::LightOfIndiaRestaurant::parse() {
|
||||
clearMenus();
|
||||
Request r;
|
||||
auto html = r.get(_url);
|
||||
if(html == "")
|
||||
return;
|
||||
clearMenus();
|
||||
HtmlParser hparse(html);
|
||||
auto &root = hparse.getRoot();
|
||||
auto container = root.find("//div[@id='content_container']")[0];
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include "../htmlparser.hpp"
|
||||
|
||||
void LunchRest::PadagaliRestaurant::parse() {
|
||||
clearMenus();
|
||||
int menu_index = 0;
|
||||
Request r;
|
||||
auto html = r.get(_url);
|
||||
if(html == "")
|
||||
return;
|
||||
clearMenus();
|
||||
HtmlParser hparse(html);
|
||||
auto &root = hparse.getRoot();
|
||||
auto days = root.find("//div[@class='glf-mor-restaurant-menu-category']");
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include "../htmlparser.hpp"
|
||||
|
||||
void LunchRest::UDrevakaRestaurant::parse() {
|
||||
clearMenus();
|
||||
int menu_index = 0;
|
||||
Request r;
|
||||
auto html = r.get(_url);
|
||||
if(html == "")
|
||||
return;
|
||||
clearMenus();
|
||||
HtmlParser hparse(html);
|
||||
auto &root = hparse.getRoot();
|
||||
auto days = root.find("//li[@class='item-day']");
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include "../htmlparser.hpp"
|
||||
|
||||
void LunchRest::UKarlaRestaurant::parse() {
|
||||
clearMenus();
|
||||
int menu_index = 0;
|
||||
Request r;
|
||||
auto html = r.get(_url);
|
||||
if(html == "")
|
||||
return;
|
||||
clearMenus();
|
||||
HtmlParser hparse(html);
|
||||
auto &root = hparse.getRoot();
|
||||
auto days = root.find("//li[@class='item-day']");
|
||||
|
Loading…
Reference in New Issue
Block a user