Rename profile → profiledata.
This commit is contained in:
parent
f0c4d63548
commit
61d591e925
|
@ -136,39 +136,39 @@ void Config::generate()
|
||||||
|
|
||||||
cout << "Instance (domain): ";
|
cout << "Instance (domain): ";
|
||||||
getline(cin, line);
|
getline(cin, line);
|
||||||
data.instance = line;
|
profiledata.instance = line;
|
||||||
|
|
||||||
data.access_token = get_access_token(line);
|
profiledata.access_token = get_access_token(line);
|
||||||
|
|
||||||
cout << "URL of the feed: ";
|
cout << "URL of the feed: ";
|
||||||
std::getline(cin, line);
|
std::getline(cin, line);
|
||||||
data.feedurl = line;
|
profiledata.feedurl = line;
|
||||||
|
|
||||||
cout << "Post only titles? [y/n]: ";
|
cout << "Post only titles? [y/n]: ";
|
||||||
std::getline(cin, line);
|
std::getline(cin, line);
|
||||||
if (line[0] == 'y')
|
if (line[0] == 'y')
|
||||||
{
|
{
|
||||||
data.titles_only = true;
|
profiledata.titles_only = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data.titles_only = false;
|
profiledata.titles_only = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Post titles as cw? [y/n]: ";
|
cout << "Post titles as cw? [y/n]: ";
|
||||||
std::getline(cin, line);
|
std::getline(cin, line);
|
||||||
if (line[0] == 'y')
|
if (line[0] == 'y')
|
||||||
{
|
{
|
||||||
data.titles_as_cw = true;
|
profiledata.titles_as_cw = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
data.titles_as_cw = false;
|
profiledata.titles_as_cw = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "Append this string to each post: ";
|
cout << "Append this string to each post: ";
|
||||||
std::getline(cin, line);
|
std::getline(cin, line);
|
||||||
data.append = line;
|
profiledata.append = line;
|
||||||
|
|
||||||
cout << "Interval between posts in seconds [30]: ";
|
cout << "Interval between posts in seconds [30]: ";
|
||||||
std::getline(cin, line);
|
std::getline(cin, line);
|
||||||
|
@ -176,7 +176,7 @@ void Config::generate()
|
||||||
{
|
{
|
||||||
line = "30";
|
line = "30";
|
||||||
}
|
}
|
||||||
data.interval = static_cast<uint32_t>(stoul(line));
|
profiledata.interval = static_cast<uint32_t>(stoul(line));
|
||||||
|
|
||||||
cout << "Maximum size of posts [500]: ";
|
cout << "Maximum size of posts [500]: ";
|
||||||
std::getline(cin, line);
|
std::getline(cin, line);
|
||||||
|
@ -184,7 +184,7 @@ void Config::generate()
|
||||||
{
|
{
|
||||||
line = "500";
|
line = "500";
|
||||||
}
|
}
|
||||||
data.max_size = stoul(line);
|
profiledata.max_size = stoul(line);
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Generated configuration.";
|
BOOST_LOG_TRIVIAL(debug) << "Generated configuration.";
|
||||||
write();
|
write();
|
||||||
|
@ -225,48 +225,48 @@ string Config::get_access_token(const string &instance) const
|
||||||
|
|
||||||
void Config::parse()
|
void Config::parse()
|
||||||
{
|
{
|
||||||
data.access_token = _json[_profile]["access_token"].asString();
|
profiledata.access_token = _json[_profile]["access_token"].asString();
|
||||||
data.append = _json[_profile]["append"].asString();
|
profiledata.append = _json[_profile]["append"].asString();
|
||||||
data.feedurl = _json[_profile]["feedurl"].asString();
|
profiledata.feedurl = _json[_profile]["feedurl"].asString();
|
||||||
for (const auto &fix : _json[_profile]["fixes"])
|
for (const auto &fix : _json[_profile]["fixes"])
|
||||||
{
|
{
|
||||||
data.fixes.push_back(fix.asString());
|
profiledata.fixes.push_back(fix.asString());
|
||||||
}
|
}
|
||||||
data.instance = _json[_profile]["instance"].asString();
|
profiledata.instance = _json[_profile]["instance"].asString();
|
||||||
if (!_json[_profile]["interval"].isNull())
|
if (!_json[_profile]["interval"].isNull())
|
||||||
{
|
{
|
||||||
data.interval =
|
profiledata.interval =
|
||||||
static_cast<uint32_t>(_json[_profile]["interval"].asUInt64());
|
static_cast<uint32_t>(_json[_profile]["interval"].asUInt64());
|
||||||
}
|
}
|
||||||
data.last_guid = _json[_profile]["last_guid"].asString();
|
profiledata.last_guid = _json[_profile]["last_guid"].asString();
|
||||||
if (!_json[_profile]["max_size"].isNull())
|
if (!_json[_profile]["max_size"].isNull())
|
||||||
{
|
{
|
||||||
data.max_size = _json[_profile]["max_size"].asUInt64();
|
profiledata.max_size = _json[_profile]["max_size"].asUInt64();
|
||||||
}
|
}
|
||||||
for (const auto &skip : _json[_profile]["skip"])
|
for (const auto &skip : _json[_profile]["skip"])
|
||||||
{
|
{
|
||||||
data.skip.push_back(skip.asString());
|
profiledata.skip.push_back(skip.asString());
|
||||||
}
|
}
|
||||||
data.titles_as_cw = _json[_profile]["titles_as_cw"].asBool();
|
profiledata.titles_as_cw = _json[_profile]["titles_as_cw"].asBool();
|
||||||
data.titles_only = _json[_profile]["titles_only"].asBool();
|
profiledata.titles_only = _json[_profile]["titles_only"].asBool();
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Read config: " << data;
|
BOOST_LOG_TRIVIAL(debug) << "Read config: " << profiledata;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Config::write()
|
void Config::write()
|
||||||
{
|
{
|
||||||
_json[_profile]["access_token"] = data.access_token;
|
_json[_profile]["access_token"] = profiledata.access_token;
|
||||||
_json[_profile]["append"] = data.append;
|
_json[_profile]["append"] = profiledata.append;
|
||||||
_json[_profile]["feedurl"] = data.feedurl;
|
_json[_profile]["feedurl"] = profiledata.feedurl;
|
||||||
// Leave fixes.
|
// Leave fixes.
|
||||||
_json[_profile]["instance"] = data.instance;
|
_json[_profile]["instance"] = profiledata.instance;
|
||||||
_json[_profile]["interval"] = data.interval;
|
_json[_profile]["interval"] = profiledata.interval;
|
||||||
_json[_profile]["last_guid"] = data.last_guid;
|
_json[_profile]["last_guid"] = profiledata.last_guid;
|
||||||
_json[_profile]["max_size"]
|
_json[_profile]["max_size"]
|
||||||
= static_cast<Json::Value::UInt64>(data.max_size);
|
= static_cast<Json::Value::UInt64>(profiledata.max_size);
|
||||||
// Leave skip.
|
// Leave skip.
|
||||||
_json[_profile]["titles_as_cw"] = data.titles_as_cw;
|
_json[_profile]["titles_as_cw"] = profiledata.titles_as_cw;
|
||||||
_json[_profile]["titles_only"] = data.titles_only;
|
_json[_profile]["titles_only"] = profiledata.titles_only;
|
||||||
|
|
||||||
ofstream file{get_filename().c_str()};
|
ofstream file{get_filename().c_str()};
|
||||||
if (file.good())
|
if (file.good())
|
||||||
|
|
|
@ -66,7 +66,7 @@ class Config
|
||||||
public:
|
public:
|
||||||
explicit Config(string profile);
|
explicit Config(string profile);
|
||||||
|
|
||||||
ProfileData data;
|
ProfileData profiledata;
|
||||||
|
|
||||||
void write();
|
void write();
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|
|
@ -45,7 +45,7 @@ bool operator !=(const Item &a, const Item &b)
|
||||||
|
|
||||||
Document::Document(Config &cfg)
|
Document::Document(Config &cfg)
|
||||||
: _cfg{cfg}
|
: _cfg{cfg}
|
||||||
, _profile{cfg.data}
|
, profiledata{cfg.data}
|
||||||
{
|
{
|
||||||
RestClient::init();
|
RestClient::init();
|
||||||
|
|
||||||
|
@ -70,20 +70,20 @@ void Document::download(const string &uri)
|
||||||
case 200:
|
case 200:
|
||||||
{
|
{
|
||||||
_raw_doc = response.body;
|
_raw_doc = response.body;
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Downloaded feed: " << _profile.feedurl;
|
BOOST_LOG_TRIVIAL(debug) << "Downloaded feed: " << profiledata.feedurl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 301:
|
case 301:
|
||||||
case 308:
|
case 308:
|
||||||
{
|
{
|
||||||
_profile.feedurl = extract_location(response.headers);
|
profiledata.feedurl = extract_location(response.headers);
|
||||||
if (_profile.feedurl.empty())
|
if (profiledata.feedurl.empty())
|
||||||
{
|
{
|
||||||
throw HTTPException{response.code};
|
throw HTTPException{response.code};
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Feed has new location (permanent): "
|
BOOST_LOG_TRIVIAL(debug) << "Feed has new location (permanent): "
|
||||||
<< _profile.feedurl;
|
<< profiledata.feedurl;
|
||||||
_cfg.write();
|
_cfg.write();
|
||||||
download();
|
download();
|
||||||
break;
|
break;
|
||||||
|
@ -99,7 +99,7 @@ void Document::download(const string &uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Feed has new location (temporary): "
|
BOOST_LOG_TRIVIAL(debug) << "Feed has new location (temporary): "
|
||||||
<< _profile.feedurl;
|
<< profiledata.feedurl;
|
||||||
download(newuri);
|
download(newuri);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ void Document::download(const string &uri)
|
||||||
|
|
||||||
void Document::download()
|
void Document::download()
|
||||||
{
|
{
|
||||||
download(_profile.feedurl);
|
download(profiledata.feedurl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Document::parse()
|
void Document::parse()
|
||||||
|
@ -145,14 +145,14 @@ void Document::parse_rss(const pt::ptree &tree)
|
||||||
{
|
{
|
||||||
guid = rssitem.get<string>("link");
|
guid = rssitem.get<string>("link");
|
||||||
}
|
}
|
||||||
if (guid == _profile.last_guid)
|
if (guid == profiledata.last_guid)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool skipthis{false};
|
bool skipthis{false};
|
||||||
string title{rssitem.get<string>("title")};
|
string title{rssitem.get<string>("title")};
|
||||||
for (const auto &skip : _profile.skip)
|
for (const auto &skip : profiledata.skip)
|
||||||
{
|
{
|
||||||
if (title.substr(0, skip.length()) == skip)
|
if (title.substr(0, skip.length()) == skip)
|
||||||
{
|
{
|
||||||
|
@ -171,7 +171,7 @@ void Document::parse_rss(const pt::ptree &tree)
|
||||||
{
|
{
|
||||||
string desc
|
string desc
|
||||||
{remove_html(rssitem.get<string>("description"))};
|
{remove_html(rssitem.get<string>("description"))};
|
||||||
for (const auto &fix : _profile.fixes)
|
for (const auto &fix : profiledata.fixes)
|
||||||
{
|
{
|
||||||
desc = regex_replace(desc, regex{fix}, "");
|
desc = regex_replace(desc, regex{fix}, "");
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ void Document::parse_rss(const pt::ptree &tree)
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Found GUID: " << item.guid;
|
BOOST_LOG_TRIVIAL(debug) << "Found GUID: " << item.guid;
|
||||||
|
|
||||||
if (_profile.last_guid.empty())
|
if (profiledata.last_guid.empty())
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(debug) << "This is the first run.";
|
BOOST_LOG_TRIVIAL(debug) << "This is the first run.";
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Config &_cfg;
|
Config &_cfg;
|
||||||
ProfileData &_profile;
|
ProfileData &_profiledata;
|
||||||
string _raw_doc;
|
string _raw_doc;
|
||||||
|
|
||||||
void parse_rss(const pt::ptree &tree);
|
void parse_rss(const pt::ptree &tree);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user