more filtering
This commit is contained in:
parent
a6abb604b0
commit
30b8286ed4
|
@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.7)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
project (rss2mastodon
|
project (rss2mastodon
|
||||||
VERSION 0.1.6
|
VERSION 0.1.7
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall")
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
**rss2mastodon** dumps RSS feeds into a mastodon account.
|
**rss2mastodon** dumps RSS feeds into a mastodon account.
|
||||||
|
It is hacked together and generally only extended/fixed when it fails.
|
||||||
|
Use at your own risk.
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
|
uint16_t max_size = 500;
|
||||||
const string filepath = string(getenv("HOME")) + "/.config/rss2mastodon/";
|
const string filepath = string(getenv("HOME")) + "/.config/rss2mastodon/";
|
||||||
|
|
||||||
void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token, string &feedurl)
|
void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token, string &feedurl)
|
||||||
|
@ -53,7 +54,7 @@ void read_config(pt::ptree &config, const string &profile, string &instance, str
|
||||||
catch (std::exception &e)
|
catch (std::exception &e)
|
||||||
{
|
{
|
||||||
// most likely no config file found
|
// most likely no config file found
|
||||||
cout << "No config file found. Building new one.\n";
|
cout << "Config file not readable. Building new one.\n";
|
||||||
const boost::filesystem::path path(filepath);
|
const boost::filesystem::path path(filepath);
|
||||||
boost::filesystem::create_directory(filepath);
|
boost::filesystem::create_directory(filepath);
|
||||||
}
|
}
|
||||||
|
@ -141,13 +142,35 @@ std::vector<string> parse_website(const string &profile, const string &xml)
|
||||||
string desc = v.second.get_child("description").data();
|
string desc = v.second.get_child("description").data();
|
||||||
string str = title + "\n\n" + desc;
|
string str = title + "\n\n" + desc;
|
||||||
|
|
||||||
|
// Some feeds contain encoded xhtml-tags >:|
|
||||||
|
std::regex relt("<");
|
||||||
|
std::regex regt(">");
|
||||||
|
std::regex reparagraph("</p><p>");
|
||||||
|
std::regex recdata1("<!\\[CDATA\\[");
|
||||||
|
std::regex recdata2("\\]\\]>");
|
||||||
|
std::regex restrip("<[^>]*>");
|
||||||
|
std::regex reindyfuckup("\\/\\* Style Definitions \\*\\/[.[:space:]]*$");
|
||||||
|
|
||||||
|
str = std::regex_replace(str, relt, "<");
|
||||||
|
str = std::regex_replace(str, regt, ">");
|
||||||
|
str = std::regex_replace(str, reparagraph, "\n\n");
|
||||||
|
str = std::regex_replace(str, recdata1, "");
|
||||||
|
str = std::regex_replace(str, recdata2, "");
|
||||||
|
str = std::regex_replace(str, restrip, "");
|
||||||
|
str = std::regex_replace(str, reindyfuckup, "");
|
||||||
|
|
||||||
for (const string &hashtag : watchwords)
|
for (const string &hashtag : watchwords)
|
||||||
{
|
{
|
||||||
std::regex rehashtag("[[:space:][:punct:]](" + hashtag + ")[[:space:][:punct:]]",
|
std::regex rehashtag("([[:space:][:punct:]^])(" + hashtag + ")([[:space:][:punct:]$])",
|
||||||
std::regex_constants::icase);
|
std::regex_constants::icase);
|
||||||
str = std::regex_replace(str, rehashtag, "#$1",
|
str = std::regex_replace(str, rehashtag, "$1#$2$3",
|
||||||
std::regex_constants::format_first_only);
|
std::regex_constants::format_first_only);
|
||||||
}
|
}
|
||||||
|
if ((str.size() + link.size()) > (max_size - 15))
|
||||||
|
{
|
||||||
|
str.resize((max_size - link.size() - 15));
|
||||||
|
str += " […]";
|
||||||
|
}
|
||||||
str += "\n\n" + link + "\n\n#bot";
|
str += "\n\n" + link + "\n\n#bot";
|
||||||
ret.push_back(str);
|
ret.push_back(str);
|
||||||
}
|
}
|
||||||
|
@ -161,15 +184,21 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
cerr << "usage: " << argv[0] << " <profile>\n";
|
cerr << "usage: " << argv[0] << " <profile> [max size]\n";
|
||||||
return 32;
|
return 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc == 3)
|
||||||
|
{
|
||||||
|
max_size == std::stoi(argv[2]);
|
||||||
|
}
|
||||||
|
|
||||||
pt::ptree config;
|
pt::ptree config;
|
||||||
string instance = "";
|
string instance = "";
|
||||||
string access_token = "";
|
string access_token = "";
|
||||||
string feedurl = "";
|
string feedurl = "";
|
||||||
const string profile = argv[1];
|
const string profile = argv[1];
|
||||||
|
std::uint16_t ret;
|
||||||
|
|
||||||
read_config(config, profile, instance, access_token, feedurl);
|
read_config(config, profile, instance, access_token, feedurl);
|
||||||
std::size_t pos = 0;
|
std::size_t pos = 0;
|
||||||
|
@ -180,19 +209,18 @@ int main(int argc, char *argv[])
|
||||||
string answer;
|
string answer;
|
||||||
string last_entry = config.get(profile + ".last_entry", "");
|
string last_entry = config.get(profile + ".last_entry", "");
|
||||||
std::vector<string> entries;
|
std::vector<string> entries;
|
||||||
http_get(hostname, path, answer);
|
ret = http_get(hostname, path, answer);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
entries = parse_website(profile, answer);
|
entries = parse_website(profile, answer);
|
||||||
|
|
||||||
if (last_entry.empty())
|
if (last_entry.empty())
|
||||||
{
|
{
|
||||||
last_entry = entries.at(1);
|
last_entry = entries.at(1);
|
||||||
config.put(profile + ".last_entry", last_entry);
|
|
||||||
}
|
}
|
||||||
else
|
config.put(profile + ".last_entry", entries.front());
|
||||||
{
|
|
||||||
config.put(profile + ".last_entry", entries.front());
|
|
||||||
}
|
|
||||||
pt::write_json(filepath + "config-" + profile + ".json", config);
|
|
||||||
|
|
||||||
bool new_content = false;
|
bool new_content = false;
|
||||||
for (auto rit = entries.rbegin(); rit != entries.rend(); ++rit)
|
for (auto rit = entries.rbegin(); rit != entries.rend(); ++rit)
|
||||||
|
@ -208,7 +236,6 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
string answer;
|
string answer;
|
||||||
std::uint16_t ret;
|
|
||||||
Mastodon::API masto(instance, access_token);
|
Mastodon::API masto(instance, access_token);
|
||||||
|
|
||||||
API::parametermap parameters =
|
API::parametermap parameters =
|
||||||
|
@ -220,11 +247,12 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
//cout << answer << '\n';
|
pt::write_json(filepath + "config-" + profile + ".json", config);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Error code: " << ret << '\n';
|
std::cerr << "Error code: " << ret << '\n';
|
||||||
|
std::cerr << answer << '\n';
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
"Botswana",
|
"Botswana",
|
||||||
"CentralAfricanRepublic",
|
"CentralAfricanRepublic",
|
||||||
"Canada",
|
"Canada",
|
||||||
"Cocos(Keeling)Islands",
|
"CocosIslands",
|
||||||
"Switzerland",
|
"Switzerland",
|
||||||
"Chile",
|
"Chile",
|
||||||
"China",
|
"China",
|
||||||
|
|
Loading…
Reference in New Issue