Added option to only post titles
This commit is contained in:
parent
6fa86a3c57
commit
bc361e38be
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastorss
|
||||
VERSION 0.4.3
|
||||
VERSION 0.5.0
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
|
|
|
@ -43,10 +43,13 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur
|
|||
file.close();
|
||||
json >> config;
|
||||
|
||||
instance = config[profile + ".instance"].asString();
|
||||
access_token = config[profile + ".access_token"].asString();
|
||||
feedurl = config[profile + ".feedurl"].asString();
|
||||
max_size = config.get(profile + ".max_size", max_size).asUInt();
|
||||
instance = config[profile]["instance"].asString();
|
||||
access_token = config[profile]["access_token"].asString();
|
||||
feedurl = config[profile]["feedurl"].asString();
|
||||
if (!config[profile]["max_size"].isNull())
|
||||
{
|
||||
max_size = config[profile]["max_size"].asUInt();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -58,7 +61,7 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur
|
|||
{
|
||||
cout << "Instance: ";
|
||||
cin >> instance;
|
||||
config[profile + ".instance"] = instance;
|
||||
config[profile]["instance"] = instance;
|
||||
config_changed = true;
|
||||
}
|
||||
if (access_token.empty())
|
||||
|
@ -87,7 +90,7 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur
|
|||
access_token);
|
||||
if (ret == 0)
|
||||
{
|
||||
config[profile + ".access_token"] = access_token;
|
||||
config[profile]["access_token"] = access_token;
|
||||
config_changed = true;
|
||||
}
|
||||
else
|
||||
|
@ -107,7 +110,22 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur
|
|||
{
|
||||
cout << "feedurl: ";
|
||||
cin >> feedurl;
|
||||
config[profile + ".feedurl"] = feedurl;
|
||||
config[profile]["feedurl"] = feedurl;
|
||||
config_changed = true;
|
||||
}
|
||||
if (!config[profile]["titles_only"].asBool())
|
||||
{
|
||||
string titles_only;
|
||||
cout << "post only titles? [y/n]: ";
|
||||
cin >> titles_only;
|
||||
if (titles_only[0] == 'y')
|
||||
{
|
||||
config[profile]["titles_only"] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
config[profile]["titles_only"] = false;
|
||||
}
|
||||
config_changed = true;
|
||||
}
|
||||
if (config_changed)
|
||||
|
|
|
@ -69,14 +69,14 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
entries = parse_website(answer);
|
||||
|
||||
string last_entry = config[profile + ".last_entry"].asString();
|
||||
string last_entry = config[profile]["last_entry"].asString();
|
||||
if (last_entry.empty())
|
||||
{
|
||||
// If no last_entry is stored in the config file,
|
||||
// make last_entry the second-newest entry.
|
||||
last_entry = entries.at(1);
|
||||
}
|
||||
config[profile + ".last_entry"] = entries.front();
|
||||
config[profile]["last_entry"] = entries.front();
|
||||
|
||||
bool new_content = false;
|
||||
for (auto rit = entries.rbegin(); rit != entries.rend(); ++rit)
|
||||
|
|
|
@ -83,7 +83,7 @@ std::vector<string> parse_website(const string &xml)
|
|||
}
|
||||
|
||||
// Read profile-specific hashtags or fail silently
|
||||
for (const Json::Value &value : list[profile + ".tags"])
|
||||
for (const Json::Value &value : list[profile]["tags"])
|
||||
{
|
||||
watchwords.push_back(value.asString());
|
||||
}
|
||||
|
@ -108,13 +108,18 @@ std::vector<string> parse_website(const string &xml)
|
|||
string title = v.second.get_child("title").data();
|
||||
string link = v.second.get_child("link").data();
|
||||
string desc = v.second.get_child("description").data();
|
||||
string str = title + "\n\n" + desc;
|
||||
|
||||
string str = title;
|
||||
if (!config[profile]["titles_only"])
|
||||
{
|
||||
str += "\n\n" + desc;
|
||||
}
|
||||
|
||||
bool skipthis = false;
|
||||
try
|
||||
{
|
||||
// Skip entries beginning with this text
|
||||
for (const Json::Value &v : config[profile + ".skip"])
|
||||
for (const Json::Value &v : config[profile]["skip"])
|
||||
{
|
||||
const string skip = v.asString();
|
||||
if (!skip.empty())
|
||||
|
@ -180,7 +185,7 @@ std::vector<string> parse_website(const string &xml)
|
|||
// Read regular expressions from the config file and delete all matches.
|
||||
void individual_fixes(string &str)
|
||||
{
|
||||
for (const Json::Value &v : config[profile + ".fixes"])
|
||||
for (const Json::Value &v : config[profile]["fixes"])
|
||||
{
|
||||
std::regex refix(v.asString());
|
||||
str = std::regex_replace(str, refix, "");
|
||||
|
|
Loading…
Reference in New Issue
Block a user