Parse watchwords only once.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
90f9cecf7b
commit
937b08ff85
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <list>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -38,7 +37,6 @@ using boost::regex;
|
||||||
using boost::regex_replace;
|
using boost::regex_replace;
|
||||||
using std::transform;
|
using std::transform;
|
||||||
using std::ifstream;
|
using std::ifstream;
|
||||||
using std::list;
|
|
||||||
using std::istringstream;
|
using std::istringstream;
|
||||||
using std::stringstream;
|
using std::stringstream;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -127,6 +125,7 @@ void Document::download()
|
||||||
|
|
||||||
void Document::parse()
|
void Document::parse()
|
||||||
{
|
{
|
||||||
|
parse_watchwords();
|
||||||
pt::ptree tree;
|
pt::ptree tree;
|
||||||
istringstream iss{_raw_doc};
|
istringstream iss{_raw_doc};
|
||||||
pt::read_xml(iss, tree);
|
pt::read_xml(iss, tree);
|
||||||
|
@ -242,6 +241,19 @@ string Document::extract_location(const RestClient::HeaderFields &headers) const
|
||||||
}
|
}
|
||||||
|
|
||||||
string Document::add_hashtags(const string &text)
|
string Document::add_hashtags(const string &text)
|
||||||
|
{
|
||||||
|
string out{text};
|
||||||
|
for (const auto &tag : _watchwords)
|
||||||
|
{
|
||||||
|
regex re_tag("([[:space:][:punct:]]|^)("
|
||||||
|
+ tag + ")([[:space:][:punct:]]|$)", regex::icase);
|
||||||
|
out = regex_replace(out, re_tag, "$1#$2$3", boost::format_first_only);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Document::parse_watchwords()
|
||||||
{
|
{
|
||||||
Json::Value json;
|
Json::Value json;
|
||||||
const auto filepath = _cfg.get_config_dir() /= "watchwords.json";
|
const auto filepath = _cfg.get_config_dir() /= "watchwords.json";
|
||||||
|
@ -259,25 +271,14 @@ string Document::add_hashtags(const string &text)
|
||||||
+ (_cfg.get_config_dir() /= "watchwords.json").string()};
|
+ (_cfg.get_config_dir() /= "watchwords.json").string()};
|
||||||
}
|
}
|
||||||
|
|
||||||
list<string> watchwords;
|
|
||||||
const auto &tags_profile = json[_cfg.profile]["tags"];
|
const auto &tags_profile = json[_cfg.profile]["tags"];
|
||||||
const auto &tags_global = json["global"]["tags"];
|
const auto &tags_global = json["global"]["tags"];
|
||||||
transform(tags_profile.begin(), tags_profile.end(),
|
transform(tags_profile.begin(), tags_profile.end(),
|
||||||
std::back_inserter(watchwords),
|
std::back_inserter(_watchwords),
|
||||||
[](const Json::Value &value) { return value.asString(); });
|
[](const Json::Value &value) { return value.asString(); });
|
||||||
transform(tags_global.begin(), tags_global.end(),
|
transform(tags_global.begin(), tags_global.end(),
|
||||||
std::back_inserter(watchwords),
|
std::back_inserter(_watchwords),
|
||||||
[](const Json::Value &value) { return value.asString(); });
|
[](const Json::Value &value) { return value.asString(); });
|
||||||
|
|
||||||
string out{text};
|
|
||||||
for (const auto &tag : watchwords)
|
|
||||||
{
|
|
||||||
regex re_tag("([[:space:][:punct:]]|^)("
|
|
||||||
+ tag + ")([[:space:][:punct:]]|$)", regex::icase);
|
|
||||||
out = regex_replace(out, re_tag, "$1#$2$3", boost::format_first_only);
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,7 @@ private:
|
||||||
Config &_cfg;
|
Config &_cfg;
|
||||||
ProfileData &_profiledata;
|
ProfileData &_profiledata;
|
||||||
string _raw_doc;
|
string _raw_doc;
|
||||||
|
list<string> _watchwords;
|
||||||
|
|
||||||
void parse_rss(const pt::ptree &tree);
|
void parse_rss(const pt::ptree &tree);
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
@ -78,6 +79,7 @@ private:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
string extract_location(const RestClient::HeaderFields &headers) const;
|
string extract_location(const RestClient::HeaderFields &headers) const;
|
||||||
string add_hashtags(const string &text);
|
string add_hashtags(const string &text);
|
||||||
|
void parse_watchwords();
|
||||||
};
|
};
|
||||||
} // namespace mastorss
|
} // namespace mastorss
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue