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:
image: plugins/download
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
gcc8:

View File

@ -14,7 +14,8 @@ The documentation is far from complete, sorry.
* [cmake](https://cmake.org/) (tested: 3.9 / 3.12)
* [boost](http://www.boost.org/) (tested: 1.65 / 1.62)
* [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)
## Get sourcecode
@ -36,10 +37,10 @@ Install with `make install`.
# Usage
Put `watchwords.json` into `~/.config/mastorss/`. Launch with profile name.
The 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`.
In the first run only the newest entry is tooted.
Put `watchwords.json` into `~/.config/mastorss/`. Launch with profile name. The
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`. In the
first run only the newest entry is tooted.
The profile can't be named "global".
@ -81,7 +82,9 @@ plus:
# Copyright
Copyright © 2018 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
This program comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
``` text
Copyright © 2018, 2019 tastytea <tastytea@tastytea.de>.
License GPLv3: GNU GPL version 3 <https://www.gnu.org/licenses/gpl-3.0.html>.
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.
* 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
* 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";
string client_id, client_secret, url;
Mastodon::API masto(instance, "");
std::uint16_t ret = masto.register_app1("mastorss",
"urn:ietf:wg:oauth:2.0:oob",
"write",
"https://schlomp.space/tastytea/mastorss",
client_id,
client_secret,
url);
if (ret == 0)
Mastodon::return_call ret
= masto.register_app1("mastorss",
"urn:ietf:wg:oauth:2.0:oob",
"write",
"https://schlomp.space/tastytea/mastorss",
client_id,
client_secret,
url);
if (!ret)
{
string code;
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",
code,
access_token);
if (ret == 0)
if (!ret)
{
config[profile]["access_token"] = access_token;
config_changed = true;
}
else
{
cerr << "Error code: " << ret << '\n';
return ret;
cerr << "Error code: " << ret.error_code << '\n';
return ret.error_code;
}
}
else
{
cerr << "Error code: " << ret << '\n';
return ret;
cerr << "Error code: " << ret.error_code << '\n';
return ret.error_code;
}
}

View File

@ -1,5 +1,5 @@
/* 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
* it under the terms of the GNU General Public License as published by
@ -27,10 +27,12 @@
#include "version.hpp"
#include "mastorss.hpp"
using Mastodon::API;
using namespace Mastodon;
using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::string;
using std::this_thread::sleep_for;
using std::chrono::seconds;
@ -98,42 +100,54 @@ int main(int argc, char *argv[])
continue;
}
Mastodon::Easy::Status answer;
Mastodon::Easy masto(instance, access_token);
Easy::return_entity<Easy::Status> ret_status;
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:
std::cerr << "Error " << ret << ": Network error\n";
break;
case 16:
std::cerr << "Error " << ret << ": Timeout\n";
break;
case 403:
std::cerr << "Error " << ret << ": Forbidden\n";
break;
case 404:
std::cerr << "Error " << ret << ": Not found\n";
break;
case 503:
std::cerr << "Error " << ret << ": Service Unavailable\n";
break;
default:
std::cerr << "Error " << ret << '\n';
case 110:
{
cerr << "Error " << err << ": Timeout\n";
break;
}
case 111:
{
cerr << "Error " << err << ": Connection refused\n";
cerr << "HTTP Error " << ret_status.http_error_code << endl;
break;
}
case 113:
{
cerr << "Error " << err << ": Could not reach host.\n";
break;
}
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;
}
if (answer.to_object().isNull())
if (!ret_status.entity.valid())
{
std::cerr << "Could not send post for unknown reasons.\n";
std::cerr << "Please file a bug at <https://schlomp.space/tastytea/mastorss/issues>.\n";
cerr << "Could not send post for unknown reasons.\n";
cerr << "Please file a bug at "
"<https://schlomp.space/tastytea/mastorss/issues>.\n";
return 1;
}

View File

@ -1,5 +1,5 @@
/* 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
* 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 = "";
if (config[profile]["titles_as_cw"].asBool())
{
status.spoiler_text(Mastodon::API::unescape_html(title));
status.spoiler_text(Mastodon::unescape_html(title));
}
else
{
@ -130,7 +130,7 @@ std::vector<Mastodon::Easy::Status> parse_feed(const string &xml)
continue;
}
content = Mastodon::API::unescape_html(content);
content = Mastodon::unescape_html(content);
// Try to turn the HTML into human-readable text
std::regex reparagraph("<p>");