More renaming.
This commit is contained in:
parent
a692e00128
commit
2b0a091e87
|
@ -45,7 +45,7 @@ bool operator !=(const Item &a, const Item &b)
|
||||||
|
|
||||||
Document::Document(Config &cfg)
|
Document::Document(Config &cfg)
|
||||||
: _cfg{cfg}
|
: _cfg{cfg}
|
||||||
, profiledata{cfg.data}
|
, _profiledata{_cfg.profiledata}
|
||||||
{
|
{
|
||||||
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: " << profiledata.feedurl;
|
BOOST_LOG_TRIVIAL(debug) << "Downloaded feed: " << _profiledata.feedurl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 301:
|
case 301:
|
||||||
case 308:
|
case 308:
|
||||||
{
|
{
|
||||||
profiledata.feedurl = extract_location(response.headers);
|
_profiledata.feedurl = extract_location(response.headers);
|
||||||
if (profiledata.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): "
|
||||||
<< profiledata.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): "
|
||||||
<< profiledata.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(profiledata.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 == profiledata.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 : profiledata.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 : profiledata.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 (profiledata.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;
|
||||||
|
|
12
src/main.cpp
12
src/main.cpp
|
@ -90,25 +90,25 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const string_view profile{args[1]};
|
const string_view profilename{args[1]};
|
||||||
BOOST_LOG_TRIVIAL(debug) << "Using profile: " << profile;
|
BOOST_LOG_TRIVIAL(debug) << "Using profile: " << profilename;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Config cfg{profile.data()};
|
Config cfg{profilename.data()};
|
||||||
Document doc{cfg};
|
Document doc{cfg};
|
||||||
doc.parse();
|
doc.parse();
|
||||||
|
|
||||||
MastoAPI masto{cfg.data};
|
MastoAPI masto{cfg.profiledata};
|
||||||
if (!doc.new_items.empty())
|
if (!doc.new_items.empty())
|
||||||
{
|
{
|
||||||
for (const auto &item : doc.new_items)
|
for (const auto &item : doc.new_items)
|
||||||
{
|
{
|
||||||
masto.post_item(item);
|
masto.post_item(item);
|
||||||
cfg.data.last_guid = item.guid;
|
cfg.profiledata.last_guid = item.guid;
|
||||||
if (item != *doc.new_items.rbegin())
|
if (item != *doc.new_items.rbegin())
|
||||||
{ // Don't sleep if this is the last item.
|
{ // Don't sleep if this is the last item.
|
||||||
sleep_for(seconds(cfg.data.interval));
|
sleep_for(seconds(cfg.profiledata.interval));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cfg.write();
|
cfg.write();
|
||||||
|
|
Loading…
Reference in New Issue