Added configurable interval between posts to prevent flooding and to allow compliance with newsbots.eu.

This commit is contained in:
tastytea 2018-09-20 05:06:10 +02:00
parent d54d6513b6
commit 257a7dbb93
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
5 changed files with 19 additions and 5 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.6)
project (mastorss
VERSION 0.7.7
VERSION 0.8.0
LANGUAGES CXX
)

View File

@ -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();

View File

@ -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.

View File

@ -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<Mastodon::Easy::Status> parse_website(const string &xml);
std::vector<Mastodon::Easy::Status> parse_feed(const string &xml);
void individual_fixes(string &str);
const std::uint16_t http_get(const string &feedurl,

View File

@ -34,7 +34,7 @@ using std::cerr;
using std::string;
namespace pt = boost::property_tree;
std::vector<Mastodon::Easy::Status> parse_website(const string &xml)
std::vector<Mastodon::Easy::Status> parse_feed(const string &xml)
{
Json::Value list;
std::vector<string> watchwords;