Compare commits

...

17 Commits
0.13.0 ... main

Author SHA1 Message Date
tastytea 87760bba2d
Print error messages from servers in debug output.
continuous-integration/drone/push Build is passing Details
2021-08-18 18:36:44 +02:00
tastytea 5275c1d9e3
Make Document::remove_html static.
continuous-integration/drone/push Build is passing Details
2021-07-12 23:39:00 +02:00
tastytea 2ad4b46551
Replace <br> with newline. 2021-07-12 23:35:53 +02:00
tastytea 59f0302281
Move usage information above install instructions.
continuous-integration/drone/push Build is passing Details
2021-05-17 23:35:10 +02:00
tastytea 344abb6a29
Add repology badge.
continuous-integration/drone/push Build was killed Details
2021-05-17 23:34:04 +02:00
tastytea 86f5c45172
Fix documentation of the “fixes” config option.
continuous-integration/drone/push Build is passing Details
2021-01-18 23:48:03 +01:00
tastytea 5e2bfe13d4
Clarify when “fixes” and “replacements” apply.
continuous-integration/drone/push Build is passing Details
2021-01-16 19:59:53 +01:00
tastytea 4ded077988
Version bump 0.13.1.
continuous-integration/drone/push Build is passing Details
2020-12-15 10:08:27 +01:00
tastytea a80b4237cb
Make ZSH_COMPLETION_DIR a bit more portable.
continuous-integration/drone/push Build is passing Details
2020-12-03 21:23:07 +01:00
tastytea 020559841c
Re-add BUILD_SHARED_LIBS.
We use it as indicator if boost should be linked dynamically.
2020-12-03 21:22:05 +01:00
tastytea cbf3f3f3ac
Document build options.
continuous-integration/drone/push Build is failing Details
2020-12-03 21:05:13 +01:00
tastytea 91373abfc5
Install Zsh completion. 2020-12-03 21:05:00 +01:00
tastytea f0c00ad825
Add Zsh completion. 2020-12-03 20:44:57 +01:00
tastytea 4d0cebdec2
Update manpage. 2020-12-03 20:18:54 +01:00
tastytea 568ac5bd4f
Add --dry-run to --help output and add advice to look at manpage. 2020-12-03 17:41:27 +01:00
tastytea baf3e207cf
Update Gentoo package installation.
continuous-integration/drone/push Build is passing Details
2020-11-29 05:05:35 +01:00
tastytea c47aac8dd2
Catch CURLExceptions from curl_wrapper.
continuous-integration/drone/push Build is passing Details
2020-11-29 04:57:49 +01:00
9 changed files with 76 additions and 21 deletions

View File

@ -8,17 +8,21 @@ endif()
# Global build options.
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build.")
option(BUILD_SHARED_LIBS "Build shared libraries." YES)
option(BUILD_SHARED_LIBS "Build shared libraries." YES) # Needed for boost.
project (mastorss
VERSION 0.13.0
VERSION 0.13.1
DESCRIPTION "Another RSS to Mastodon bot."
LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(GNUInstallDirs)
# Project build options.
option(WITH_MAN "Compile and install manpage." YES)
option(WITH_COMPLETIONS "Install Zsh completions." YES)
set(ZSH_COMPLETION_DIR "${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions"
CACHE STRING "Installation directory for Zsh completions.")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
@ -34,6 +38,10 @@ if(WITH_MAN)
add_subdirectory(man)
endif()
if(WITH_COMPLETIONS)
add_subdirectory(completions)
endif()
install(FILES watchwords.json
DESTINATION "${CMAKE_INSTALL_DATADIR}/mastorss")

View File

@ -16,15 +16,22 @@
*mastorss* reads RSS feeds and posts the items via the Mastodon API. Does not
support Atom at the moment.
== Usage
See link:{uri-branch-main}/man/mastorss.1.adoc[manpage].
== Install
[alt="Packaging status" link=https://repology.org/project/mastorss/versions]
image::https://repology.org/badge/vertical-allrepos/mastorss.svg[]
=== Gentoo
[source,shell]
--------------------------------------------------------------------------------
eselect repository enable tastytea
eselect repository enable guru
echo 'net-misc/mastorss' >> /etc/portage/package.accept_keywords/mastorss
emaint sync -r tastytea
emaint sync -r guru
emerge -a net-misc/mastorss
--------------------------------------------------------------------------------
@ -68,10 +75,12 @@ cmake ..
cmake --build .
--------------------------------------------------------------------------------
.CMake options:
* `-DCMAKE_BUILD_TYPE=Debug` Debug build.
* `-DWITH_MAN=NO` Don't install manpage.
* `-DWITH_COMPLETIONS=NO` Don't install completions.
* `-DZSH_COMPLETION_DIR` Change installation directory for Zsh completions.
Install with `make install`.
== Usage
See link:{uri-branch-main}/man/mastorss.1.adoc[manpage].
include::{uri-base}/raw/branch/main/CONTRIBUTING.adoc[]

View File

@ -0,0 +1 @@
install(FILES "_mastorss" DESTINATION "${ZSH_COMPLETION_DIR}")

26
completions/_mastorss Normal file
View File

@ -0,0 +1,26 @@
# -*- mode: shell-script; -*-
#compdef mastorss
local context state state_descr line
typeset -A opt_args
_arguments \
"(- *)--dry-run[Do everything like normal, but don't post anything and don't update the config file.]" \
"(- *)--help[Show a short help message.]" \
"(- *)--version[Show version, copyright and license.]" \
"::Profile:->profiles"
case "$state" in
profiles)
# Find config dir.
local config_dir="${XDG_CONFIG_HOME}"
[[ -z "${config_dir}" ]] && config_dir="${HOME}/.config"
config_dir+="/mastorss"
# Extract profile names from config files.
for file in "${config_dir}"/config-*; do
profile="${file/*config-/}"
compadd ${profile%.json}
done
;;
esac

View File

@ -2,7 +2,7 @@
:doctype: manpage
:Author: tastytea
:Email: tastytea@tastytea.de
:Date: 2020-11-21
:Date: 2021-01-18
:Revision: 0.0.0
:man source: mastorss
:man manual: General Commands Manual
@ -28,7 +28,7 @@ file. The initial config file is still created, if the profile doesn't
exist. The interval between posts is set to 1 second.
*--help*::
Show help message.
Show a short help message.
*--version*::
Show version, copyright and license.
@ -67,8 +67,9 @@ This string will be appended to every post.
The URI of the source feed.
*fixes*::
Array of regular expressions that should be deleted from the text. For
information about the syntax see *perlre*(1).
Array of regular expressions that should be deleted from the text. Applies to
RSS descriptions (before the HTML is stripped). For information about the syntax
see *perlre*(1).
*instance*::
Hostname of the instance you're using to post.
@ -97,9 +98,9 @@ content warning) of the post.
If true, only post titles, no descriptions.
*replacements*::
Object with a list of regular expressions and replacements. Applies to posts,
subjects and links, but not to the string in _append_. For information about the
syntax see *perlre*(1).
Object with a list of regular expressions and replacements. Applies to posts
(after the HTML is stripped), subjects and links, but not to the string in
_append_. For information about the syntax see *perlre*(1).
*add_hashtags*::
If true, replace words with hashtags according to `watchwords.json`.

View File

@ -1,5 +1,5 @@
/* This file is part of mastorss.
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
* Copyright © 2019-2021 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
@ -233,11 +233,12 @@ void Document::parse_rss(const pt::ptree &tree)
}
}
string Document::remove_html(string html) const
string Document::remove_html(string html)
{
html = mastodonpp::unescape_html(html); // Decode HTML entities.
html = regex_replace(html, regex{"<p>"}, "\n\n");
html = regex_replace(html, regex{"<br>"}, "\n");
const list re_list{regex{R"(<!\[CDATA\[)"}, // CDATA beginning.
regex{R"(\]\]>)"}, // CDATA end.

View File

@ -1,5 +1,5 @@
/* This file is part of mastorss.
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
* Copyright © 2019-2021 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
@ -84,7 +84,7 @@ private:
*/
void download(const string &uri, bool temp_redirect = false);
void parse_rss(const pt::ptree &tree);
[[nodiscard]] string remove_html(string html) const;
[[nodiscard]] static string remove_html(string html);
[[nodiscard]] static string
extract_location(const curl_wrapper::answer &answer);
string add_hashtags(const string &text);

View File

@ -15,6 +15,7 @@
*/
#include "config.hpp"
#include "curl_wrapper.hpp"
#include "document.hpp"
#include "exceptions.hpp"
#include "mastoapi.hpp"
@ -71,7 +72,8 @@ void print_version()
void print_help(const string_view command)
{
cerr << "Usage: " << command << " [--version|--help] <profile>\n";
cerr << "Usage: " << command << " [--version|--help|--dry-run] <profile>\n"
<< "See manpage for details.\n";
}
int run(const string_view profile_name, const bool dry_run)
@ -124,6 +126,11 @@ int run(const string_view profile_name, const bool dry_run)
cerr << e.what() << '\n';
return error::network;
}
catch (const curl_wrapper::CURLException &e)
{
cerr << e.what() << '\n';
return error::network;
}
catch (const Json::RuntimeError &e)
{
cerr << "JSON error:\n" << e.what() << '\n';

View File

@ -1,5 +1,5 @@
/* This file is part of mastorss.
* Copyright © 2019, 2020 tastytea <tastytea@tastytea.de>
* Copyright © 2019-2021 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
@ -124,6 +124,8 @@ void MastoAPI::post_item(const Item &item, bool dry_run)
{
if (ret.http_status != 200)
{
BOOST_LOG_TRIVIAL(debug) << "Error message from server: "
<< ret.body;
throw HTTPException{ret.http_status};
}
throw CURLException{ret.curl_error_code};