Added configurable interval between posts to prevent flooding and to allow compliance with newsbots.eu.
This commit is contained in:
parent
d54d6513b6
commit
257a7dbb93
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.6)
|
cmake_minimum_required (VERSION 3.6)
|
||||||
project (mastorss
|
project (mastorss
|
||||||
VERSION 0.7.7
|
VERSION 0.8.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,18 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur
|
||||||
config[profile]["append"] = append;
|
config[profile]["append"] = append;
|
||||||
config_changed = true;
|
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)
|
if (config_changed)
|
||||||
{
|
{
|
||||||
write_config();
|
write_config();
|
||||||
|
|
|
@ -32,6 +32,8 @@ using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::cin;
|
using std::cin;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::this_thread::sleep_for;
|
||||||
|
using std::chrono::seconds;
|
||||||
|
|
||||||
// Initialize global variables
|
// Initialize global variables
|
||||||
std::uint16_t max_size = 500;
|
std::uint16_t max_size = 500;
|
||||||
|
@ -70,7 +72,7 @@ int main(int argc, char *argv[])
|
||||||
std::cerr << answer << '\n';
|
std::cerr << answer << '\n';
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
entries = parse_website(answer);
|
entries = parse_feed(answer);
|
||||||
|
|
||||||
string last_entry = config[profile]["last_entry"].asString();
|
string last_entry = config[profile]["last_entry"].asString();
|
||||||
if (last_entry.empty())
|
if (last_entry.empty())
|
||||||
|
@ -114,7 +116,7 @@ int main(int argc, char *argv[])
|
||||||
return ret;
|
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.
|
// Write the new last_entry only if no error happened.
|
||||||
|
|
|
@ -17,7 +17,7 @@ extern std::string profile;
|
||||||
std::uint16_t read_config(string &instance, string &access_token, string &feedurl);
|
std::uint16_t read_config(string &instance, string &access_token, string &feedurl);
|
||||||
const bool write_config();
|
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);
|
void individual_fixes(string &str);
|
||||||
|
|
||||||
const std::uint16_t http_get(const string &feedurl,
|
const std::uint16_t http_get(const string &feedurl,
|
||||||
|
|
|
@ -34,7 +34,7 @@ using std::cerr;
|
||||||
using std::string;
|
using std::string;
|
||||||
namespace pt = boost::property_tree;
|
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;
|
Json::Value list;
|
||||||
std::vector<string> watchwords;
|
std::vector<string> watchwords;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user