diff --git a/main.cpp b/main.cpp index 833ed5b..c251413 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,13 @@ std::vector days = {"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY"}; std::vector> 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(); ssl_settings->set_http_disabled(true); ssl_settings->set_private_key(restbed::Uri("file:///home/zvon/data/programming/lunch-rest/example.key")); diff --git a/restaurants/alcapone.cpp b/restaurants/alcapone.cpp index 0f02c26..9734ef7 100644 --- a/restaurants/alcapone.cpp +++ b/restaurants/alcapone.cpp @@ -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"); diff --git a/restaurants/lightofindia.cpp b/restaurants/lightofindia.cpp index 87903ed..1dbd8a9 100644 --- a/restaurants/lightofindia.cpp +++ b/restaurants/lightofindia.cpp @@ -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]; diff --git a/restaurants/padagali.cpp b/restaurants/padagali.cpp index fc6a958..f74b632 100644 --- a/restaurants/padagali.cpp +++ b/restaurants/padagali.cpp @@ -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']"); diff --git a/restaurants/udrevaka.cpp b/restaurants/udrevaka.cpp index 1c51de6..8ffd0ed 100644 --- a/restaurants/udrevaka.cpp +++ b/restaurants/udrevaka.cpp @@ -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']"); diff --git a/restaurants/ukarla.cpp b/restaurants/ukarla.cpp index 00a407e..c81ac62 100644 --- a/restaurants/ukarla.cpp +++ b/restaurants/ukarla.cpp @@ -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']");