From 257a7dbb9309d1d7cef4bc27c4491973a457fbed Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 20 Sep 2018 05:06:10 +0200 Subject: [PATCH] Added configurable interval between posts to prevent flooding and to allow compliance with newsbots.eu. --- CMakeLists.txt | 2 +- src/config.cpp | 12 ++++++++++++ src/mastorss.cpp | 6 ++++-- src/mastorss.hpp | 2 +- src/parse.cpp | 2 +- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b97ff60..751ccbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.6) project (mastorss - VERSION 0.7.7 + VERSION 0.8.0 LANGUAGES CXX ) diff --git a/src/config.cpp b/src/config.cpp index 9d16034..5be2b29 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -156,6 +156,18 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur config[profile]["append"] = append; config_changed = true; } + if (config[profile]["interval"].isNull()) + { + string interval; + cout << "Interval between posts in seconds [60]: "; + cin >> interval; + if (interval.empty()) + { + interval = "60"; + } + config[profile]["interval"] = std::stoul(interval); + config_changed = true; + } if (config_changed) { write_config(); diff --git a/src/mastorss.cpp b/src/mastorss.cpp index 365f38a..2466905 100644 --- a/src/mastorss.cpp +++ b/src/mastorss.cpp @@ -32,6 +32,8 @@ using std::cout; using std::cerr; using std::cin; using std::string; +using std::this_thread::sleep_for; +using std::chrono::seconds; // Initialize global variables std::uint16_t max_size = 500; @@ -70,7 +72,7 @@ int main(int argc, char *argv[]) std::cerr << answer << '\n'; return ret; } - entries = parse_website(answer); + entries = parse_feed(answer); string last_entry = config[profile]["last_entry"].asString(); if (last_entry.empty()) @@ -114,7 +116,7 @@ int main(int argc, char *argv[]) return ret; } - std::this_thread::sleep_for(std::chrono::seconds(2)); + sleep_for(seconds(config[profile]["interval"].asUInt64())); } // Write the new last_entry only if no error happened. diff --git a/src/mastorss.hpp b/src/mastorss.hpp index cca5e67..e03263b 100644 --- a/src/mastorss.hpp +++ b/src/mastorss.hpp @@ -17,7 +17,7 @@ extern std::string profile; std::uint16_t read_config(string &instance, string &access_token, string &feedurl); const bool write_config(); -std::vector parse_website(const string &xml); +std::vector parse_feed(const string &xml); void individual_fixes(string &str); const std::uint16_t http_get(const string &feedurl, diff --git a/src/parse.cpp b/src/parse.cpp index 390c1b0..985a928 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -34,7 +34,7 @@ using std::cerr; using std::string; namespace pt = boost::property_tree; -std::vector parse_website(const string &xml) +std::vector parse_feed(const string &xml) { Json::Value list; std::vector watchwords;