Ported to mastoson-cpp 0.105.0.

This commit is contained in:
tastytea 2019-04-21 04:00:55 +02:00
parent d02ca95345
commit 7b3cb678ca
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
5 changed files with 73 additions and 55 deletions

View File

@ -2,7 +2,7 @@ pipeline:
download: download:
image: plugins/download image: plugins/download
pull: true pull: true
source: https://schlomp.space/attachments/74cfa418-aecd-403d-9abe-ab3f5e3cce48 source: https://schlomp.space/attachments/e1c1e64b-1192-4037-aad4-95238ad648b0
destination: mastodon-cpp.deb destination: mastodon-cpp.deb
gcc8: gcc8:

View File

@ -14,7 +14,8 @@ The documentation is far from complete, sorry.
* [cmake](https://cmake.org/) (tested: 3.9 / 3.12) * [cmake](https://cmake.org/) (tested: 3.9 / 3.12)
* [boost](http://www.boost.org/) (tested: 1.65 / 1.62) * [boost](http://www.boost.org/) (tested: 1.65 / 1.62)
* [curlpp](http://www.curlpp.org/) (tested: 0.8) * [curlpp](http://www.curlpp.org/) (tested: 0.8)
* [mastodon-cpp](https://schlomp.space/tastytea/mastodon-cpp) (at least: 0.18.9) * [mastodon-cpp](https://schlomp.space/tastytea/mastodon-cpp) (at least:
0.105.0)
* [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8 / 1.7) * [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8 / 1.7)
## Get sourcecode ## Get sourcecode
@ -36,10 +37,10 @@ Install with `make install`.
# Usage # Usage
Put `watchwords.json` into `~/.config/mastorss/`. Launch with profile name. Put `watchwords.json` into `~/.config/mastorss/`. Launch with profile name. The
The first occurence of every watchword in an RSS item will be turned into a hashtag. first occurence of every watchword in an RSS item will be turned into a hashtag.
For profile-specific watchwords see the example in `watchwords.json`. For profile-specific watchwords see the example in `watchwords.json`. In the
In the first run only the newest entry is tooted. first run only the newest entry is tooted.
The profile can't be named "global". The profile can't be named "global".
@ -81,7 +82,9 @@ plus:
# Copyright # Copyright
Copyright © 2018 tastytea <tastytea@tastytea.de>. ``` text
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>. Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software, License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
and you are welcome to redistribute it under certain conditions. This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
```

View File

@ -1,5 +1,5 @@
/* This file is part of mastorss. /* This file is part of mastorss.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -74,14 +74,15 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur
cout << "No access token found.\n"; cout << "No access token found.\n";
string client_id, client_secret, url; string client_id, client_secret, url;
Mastodon::API masto(instance, ""); Mastodon::API masto(instance, "");
std::uint16_t ret = masto.register_app1("mastorss", Mastodon::return_call ret
"urn:ietf:wg:oauth:2.0:oob", = masto.register_app1("mastorss",
"write", "urn:ietf:wg:oauth:2.0:oob",
"https://schlomp.space/tastytea/mastorss", "write",
client_id, "https://schlomp.space/tastytea/mastorss",
client_secret, client_id,
url); client_secret,
if (ret == 0) url);
if (!ret)
{ {
string code; string code;
cout << "Visit " << url << " to authorize this application.\n"; cout << "Visit " << url << " to authorize this application.\n";
@ -93,21 +94,21 @@ std::uint16_t read_config(string &instance, string &access_token, string &feedur
"urn:ietf:wg:oauth:2.0:oob", "urn:ietf:wg:oauth:2.0:oob",
code, code,
access_token); access_token);
if (ret == 0) if (!ret)
{ {
config[profile]["access_token"] = access_token; config[profile]["access_token"] = access_token;
config_changed = true; config_changed = true;
} }
else else
{ {
cerr << "Error code: " << ret << '\n'; cerr << "Error code: " << ret.error_code << '\n';
return ret; return ret.error_code;
} }
} }
else else
{ {
cerr << "Error code: " << ret << '\n'; cerr << "Error code: " << ret.error_code << '\n';
return ret; return ret.error_code;
} }
} }

View File

@ -1,5 +1,5 @@
/* This file is part of mastorss. /* This file is part of mastorss.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -27,10 +27,12 @@
#include "version.hpp" #include "version.hpp"
#include "mastorss.hpp" #include "mastorss.hpp"
using Mastodon::API; using namespace Mastodon;
using std::cout; using std::cout;
using std::cerr; using std::cerr;
using std::cin; using std::cin;
using std::endl;
using std::string; using std::string;
using std::this_thread::sleep_for; using std::this_thread::sleep_for;
using std::chrono::seconds; using std::chrono::seconds;
@ -98,42 +100,54 @@ int main(int argc, char *argv[])
continue; continue;
} }
Mastodon::Easy::Status answer; Easy::return_entity<Easy::Status> ret_status;
Mastodon::Easy masto(instance, access_token); Mastodon::Easy::API masto(instance, access_token);
answer = masto.send_post(*rit, ret); ret_status = masto.send_post(*rit);
if (ret != 0) if (!ret_status)
{ {
switch (ret) const uint8_t err = ret_status.error_code;
switch (err)
{ {
case 15: case 110:
std::cerr << "Error " << ret << ": Network error\n"; {
break; cerr << "Error " << err << ": Timeout\n";
case 16: break;
std::cerr << "Error " << ret << ": Timeout\n"; }
break; case 111:
case 403: {
std::cerr << "Error " << ret << ": Forbidden\n"; cerr << "Error " << err << ": Connection refused\n";
break; cerr << "HTTP Error " << ret_status.http_error_code << endl;
case 404: break;
std::cerr << "Error " << ret << ": Not found\n"; }
break; case 113:
case 503: {
std::cerr << "Error " << ret << ": Service Unavailable\n"; cerr << "Error " << err << ": Could not reach host.\n";
break; break;
default: }
std::cerr << "Error " << ret << '\n'; case 192:
case 193:
{
cerr << "Error " << err << ": curlpp error\n";
break;
}
default:
{
cerr << "Error " << err << '\n';
cerr << "HTTP status " << ret_status.http_error_code << endl;
}
} }
std::cerr << answer.to_object().asString() << '\n'; cerr << ret_status.entity.to_string() << '\n';
return ret; return ret;
} }
if (answer.to_object().isNull()) if (!ret_status.entity.valid())
{ {
std::cerr << "Could not send post for unknown reasons.\n"; cerr << "Could not send post for unknown reasons.\n";
std::cerr << "Please file a bug at <https://schlomp.space/tastytea/mastorss/issues>.\n"; cerr << "Please file a bug at "
"<https://schlomp.space/tastytea/mastorss/issues>.\n";
return 1; return 1;
} }

View File

@ -1,5 +1,5 @@
/* This file is part of mastorss. /* This file is part of mastorss.
* Copyright © 2018 tastytea <tastytea@tastytea.de> * Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -83,7 +83,7 @@ std::vector<Mastodon::Easy::Status> parse_feed(const string &xml)
string content = ""; string content = "";
if (config[profile]["titles_as_cw"].asBool()) if (config[profile]["titles_as_cw"].asBool())
{ {
status.spoiler_text(Mastodon::API::unescape_html(title)); status.spoiler_text(Mastodon::unescape_html(title));
} }
else else
{ {
@ -130,7 +130,7 @@ std::vector<Mastodon::Easy::Status> parse_feed(const string &xml)
continue; continue;
} }
content = Mastodon::API::unescape_html(content); content = Mastodon::unescape_html(content);
// Try to turn the HTML into human-readable text // Try to turn the HTML into human-readable text
std::regex reparagraph("<p>"); std::regex reparagraph("<p>");