This commit is contained in:
tastytea 2018-01-26 03:35:52 +01:00
parent ee0ec8dfc0
commit 0b1c436bbb
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
4 changed files with 39 additions and 26 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.7)
include(GNUInstallDirs) include(GNUInstallDirs)
project (rss2mastodon project (rss2mastodon
VERSION 0.1.0 VERSION 0.1.1
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")

View File

@ -31,7 +31,9 @@ Install with `make install`.
# Usage # 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 ## Error codes

View File

@ -37,7 +37,7 @@ using std::string;
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) void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token, string &feedurl)
{ {
bool config_changed = false; 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); pt::read_json(filepath + "config.json", config);
instance = config.get(profile + ".instance", ""); instance = config.get(profile + ".instance", "");
access_token = config.get(profile + ".access_token", ""); access_token = config.get(profile + ".access_token", "");
feedurl = config.get(profile + ".feedurl", "");
} }
catch (std::exception &e) 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.put(profile + ".access_token", access_token);
config_changed = true; config_changed = true;
} }
if (feedurl.empty())
{
cout << "feedurl: ";
std::cin >> feedurl;
config.put(profile + ".feedurl", feedurl);
config_changed = true;
}
if (config_changed) if (config_changed)
{ {
pt::write_json(filepath + "config.json", config); pt::write_json(filepath + "config.json", config);
@ -155,14 +163,19 @@ int main(int argc, char *argv[])
pt::ptree config; pt::ptree config;
string instance = ""; string instance = "";
string access_token = ""; string access_token = "";
string feedurl = "";
const string profile = argv[1]; 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 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("anfdeutsch.com", "/feed.rss", answer); http_get(hostname, path, answer);
entries = parse_website(profile, answer); entries = parse_website(profile, answer);
config.put(profile + ".last_entry", entries.front()); config.put(profile + ".last_entry", entries.front());
@ -181,28 +194,26 @@ int main(int argc, char *argv[])
continue; continue;
} }
cout << *rit << "\n========\n"; string answer;
// string answer; std::uint16_t ret;
// std::uint16_t ret; Mastodon::API masto(instance, access_token);
// Mastodon::API masto(instance, access_token);
// masto.set_useragent("afrinticker");
// API::parametermap parameters = API::parametermap parameters =
// { {
// { "status", { entry + "\n\n#bot"} }, { "status", { *rit } },
// { "visibility", { "public" } } { "visibility", { "public" } }
// }; };
// ret = masto.post(API::v1::statuses, parameters, answer); ret = masto.post(API::v1::statuses, parameters, answer);
// if (ret == 0) if (ret == 0)
// { {
// //cout << answer << '\n'; //cout << answer << '\n';
// } }
// else else
// { {
// std::cerr << "Error code: " << ret << '\n'; std::cerr << "Error code: " << ret << '\n';
// return ret; return ret;
// } }
} }
return 0; return 0;

View File

@ -9,7 +9,7 @@
namespace pt = boost::property_tree; namespace pt = boost::property_tree;
using std::string; 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<string> parse_website(const string &profile, const string &xml); std::vector<string> parse_website(const string &profile, const string &xml);
// http.cpp // http.cpp