diff --git a/CMakeLists.txt b/CMakeLists.txt index b3a19bb..9c70e22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.7) include(GNUInstallDirs) project (rss2mastodon - VERSION 0.1.0 + VERSION 0.1.1 LANGUAGES CXX ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall") diff --git a/README.md b/README.md index c938938..0482032 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,9 @@ Install with `make install`. # Usage -… +Put watchwords.json into `~/.config/rss2mastodon/`. Launch with profile name. +In the first run nothing is tooted, only the newest entry is saved. +In the next run only newer entries are tooted. ## Error codes diff --git a/src/rss2mastodon.cpp b/src/rss2mastodon.cpp index 10a9a10..a42e3bf 100644 --- a/src/rss2mastodon.cpp +++ b/src/rss2mastodon.cpp @@ -37,7 +37,7 @@ using std::string; const string filepath = string(getenv("HOME")) + "/.config/rss2mastodon/"; -void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token) +void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token, string &feedurl) { bool config_changed = false; @@ -46,6 +46,7 @@ void read_config(pt::ptree &config, const string &profile, string &instance, str pt::read_json(filepath + "config.json", config); instance = config.get(profile + ".instance", ""); access_token = config.get(profile + ".access_token", ""); + feedurl = config.get(profile + ".feedurl", ""); } catch (std::exception &e) { @@ -69,6 +70,13 @@ void read_config(pt::ptree &config, const string &profile, string &instance, str config.put(profile + ".access_token", access_token); config_changed = true; } + if (feedurl.empty()) + { + cout << "feedurl: "; + std::cin >> feedurl; + config.put(profile + ".feedurl", feedurl); + config_changed = true; + } if (config_changed) { pt::write_json(filepath + "config.json", config); @@ -155,14 +163,19 @@ int main(int argc, char *argv[]) pt::ptree config; string instance = ""; string access_token = ""; + string feedurl = ""; const string profile = argv[1]; - read_config(config, profile, instance, access_token); + read_config(config, profile, instance, access_token, feedurl); + std::size_t pos = 0; + pos = feedurl.find("//") + 2; + const string hostname = feedurl.substr(pos, feedurl.find('/', pos) - pos); + const string path = feedurl.substr(pos + hostname.size()); string answer; string last_entry = config.get(profile + ".last_entry", ""); std::vector entries; - http_get("anfdeutsch.com", "/feed.rss", answer); + http_get(hostname, path, answer); entries = parse_website(profile, answer); config.put(profile + ".last_entry", entries.front()); @@ -181,28 +194,26 @@ int main(int argc, char *argv[]) continue; } - cout << *rit << "\n========\n"; - // string answer; - // std::uint16_t ret; - // Mastodon::API masto(instance, access_token); - // masto.set_useragent("afrinticker"); + string answer; + std::uint16_t ret; + Mastodon::API masto(instance, access_token); - // API::parametermap parameters = - // { - // { "status", { entry + "\n\n#bot"} }, - // { "visibility", { "public" } } - // }; - // ret = masto.post(API::v1::statuses, parameters, answer); + API::parametermap parameters = + { + { "status", { *rit } }, + { "visibility", { "public" } } + }; + ret = masto.post(API::v1::statuses, parameters, answer); - // if (ret == 0) - // { - // //cout << answer << '\n'; - // } - // else - // { - // std::cerr << "Error code: " << ret << '\n'; - // return ret; - // } + if (ret == 0) + { + //cout << answer << '\n'; + } + else + { + std::cerr << "Error code: " << ret << '\n'; + return ret; + } } return 0; diff --git a/src/rss2mastodon.hpp b/src/rss2mastodon.hpp index 37ef9c3..dea03df 100644 --- a/src/rss2mastodon.hpp +++ b/src/rss2mastodon.hpp @@ -9,7 +9,7 @@ namespace pt = boost::property_tree; using std::string; -void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token); +void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token, string &feedurl); std::vector parse_website(const string &profile, const string &xml); // http.cpp