Compare commits
17 Commits
Author | SHA1 | Date |
---|---|---|
tastytea | 87760bba2d | |
tastytea | 5275c1d9e3 | |
tastytea | 2ad4b46551 | |
tastytea | 59f0302281 | |
tastytea | 344abb6a29 | |
tastytea | 86f5c45172 | |
tastytea | 5e2bfe13d4 | |
tastytea | 4ded077988 | |
tastytea | a80b4237cb | |
tastytea | 020559841c | |
tastytea | cbf3f3f3ac | |
tastytea | 91373abfc5 | |
tastytea | f0c00ad825 | |
tastytea | 4d0cebdec2 | |
tastytea | 568ac5bd4f | |
tastytea | baf3e207cf | |
tastytea | c47aac8dd2 |
|
@ -8,17 +8,21 @@ endif()
|
||||||
|
|
||||||
# Global build options.
|
# Global build options.
|
||||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "The type of build.")
|
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
|
project (mastorss
|
||||||
VERSION 0.13.0
|
VERSION 0.13.1
|
||||||
DESCRIPTION "Another RSS to Mastodon bot."
|
DESCRIPTION "Another RSS to Mastodon bot."
|
||||||
LANGUAGES CXX)
|
LANGUAGES CXX)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
# Project build options.
|
# Project build options.
|
||||||
option(WITH_MAN "Compile and install manpage." YES)
|
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 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
@ -34,6 +38,10 @@ if(WITH_MAN)
|
||||||
add_subdirectory(man)
|
add_subdirectory(man)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(WITH_COMPLETIONS)
|
||||||
|
add_subdirectory(completions)
|
||||||
|
endif()
|
||||||
|
|
||||||
install(FILES watchwords.json
|
install(FILES watchwords.json
|
||||||
DESTINATION "${CMAKE_INSTALL_DATADIR}/mastorss")
|
DESTINATION "${CMAKE_INSTALL_DATADIR}/mastorss")
|
||||||
|
|
||||||
|
|
21
README.adoc
21
README.adoc
|
@ -16,15 +16,22 @@
|
||||||
*mastorss* reads RSS feeds and posts the items via the Mastodon API. Does not
|
*mastorss* reads RSS feeds and posts the items via the Mastodon API. Does not
|
||||||
support Atom at the moment.
|
support Atom at the moment.
|
||||||
|
|
||||||
|
== Usage
|
||||||
|
|
||||||
|
See link:{uri-branch-main}/man/mastorss.1.adoc[manpage].
|
||||||
|
|
||||||
== Install
|
== Install
|
||||||
|
|
||||||
|
[alt="Packaging status" link=https://repology.org/project/mastorss/versions]
|
||||||
|
image::https://repology.org/badge/vertical-allrepos/mastorss.svg[]
|
||||||
|
|
||||||
=== Gentoo
|
=== Gentoo
|
||||||
|
|
||||||
[source,shell]
|
[source,shell]
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
eselect repository enable tastytea
|
eselect repository enable guru
|
||||||
echo 'net-misc/mastorss' >> /etc/portage/package.accept_keywords/mastorss
|
echo 'net-misc/mastorss' >> /etc/portage/package.accept_keywords/mastorss
|
||||||
emaint sync -r tastytea
|
emaint sync -r guru
|
||||||
emerge -a net-misc/mastorss
|
emerge -a net-misc/mastorss
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -68,10 +75,12 @@ cmake ..
|
||||||
cmake --build .
|
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`.
|
Install with `make install`.
|
||||||
|
|
||||||
== Usage
|
|
||||||
|
|
||||||
See link:{uri-branch-main}/man/mastorss.1.adoc[manpage].
|
|
||||||
|
|
||||||
include::{uri-base}/raw/branch/main/CONTRIBUTING.adoc[]
|
include::{uri-base}/raw/branch/main/CONTRIBUTING.adoc[]
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
install(FILES "_mastorss" DESTINATION "${ZSH_COMPLETION_DIR}")
|
|
@ -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
|
|
@ -2,7 +2,7 @@
|
||||||
:doctype: manpage
|
:doctype: manpage
|
||||||
:Author: tastytea
|
:Author: tastytea
|
||||||
:Email: tastytea@tastytea.de
|
:Email: tastytea@tastytea.de
|
||||||
:Date: 2020-11-21
|
:Date: 2021-01-18
|
||||||
:Revision: 0.0.0
|
:Revision: 0.0.0
|
||||||
:man source: mastorss
|
:man source: mastorss
|
||||||
:man manual: General Commands Manual
|
: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.
|
exist. The interval between posts is set to 1 second.
|
||||||
|
|
||||||
*--help*::
|
*--help*::
|
||||||
Show help message.
|
Show a short help message.
|
||||||
|
|
||||||
*--version*::
|
*--version*::
|
||||||
Show version, copyright and license.
|
Show version, copyright and license.
|
||||||
|
@ -67,8 +67,9 @@ This string will be appended to every post.
|
||||||
The URI of the source feed.
|
The URI of the source feed.
|
||||||
|
|
||||||
*fixes*::
|
*fixes*::
|
||||||
Array of regular expressions that should be deleted from the text. For
|
Array of regular expressions that should be deleted from the text. Applies to
|
||||||
information about the syntax see *perlre*(1).
|
RSS descriptions (before the HTML is stripped). For information about the syntax
|
||||||
|
see *perlre*(1).
|
||||||
|
|
||||||
*instance*::
|
*instance*::
|
||||||
Hostname of the instance you're using to post.
|
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.
|
If true, only post titles, no descriptions.
|
||||||
|
|
||||||
*replacements*::
|
*replacements*::
|
||||||
Object with a list of regular expressions and replacements. Applies to posts,
|
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
|
(after the HTML is stripped), subjects and links, but not to the string in
|
||||||
syntax see *perlre*(1).
|
_append_. For information about the syntax see *perlre*(1).
|
||||||
|
|
||||||
*add_hashtags*::
|
*add_hashtags*::
|
||||||
If true, replace words with hashtags according to `watchwords.json`.
|
If true, replace words with hashtags according to `watchwords.json`.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of mastorss.
|
/* 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
|
* 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
|
||||||
|
@ -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 = mastodonpp::unescape_html(html); // Decode HTML entities.
|
||||||
|
|
||||||
html = regex_replace(html, regex{"<p>"}, "\n\n");
|
html = regex_replace(html, regex{"<p>"}, "\n\n");
|
||||||
|
html = regex_replace(html, regex{"<br>"}, "\n");
|
||||||
|
|
||||||
const list re_list{regex{R"(<!\[CDATA\[)"}, // CDATA beginning.
|
const list re_list{regex{R"(<!\[CDATA\[)"}, // CDATA beginning.
|
||||||
regex{R"(\]\]>)"}, // CDATA end.
|
regex{R"(\]\]>)"}, // CDATA end.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of mastorss.
|
/* 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
|
* 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
|
||||||
|
@ -84,7 +84,7 @@ private:
|
||||||
*/
|
*/
|
||||||
void download(const string &uri, bool temp_redirect = false);
|
void download(const string &uri, bool temp_redirect = false);
|
||||||
void parse_rss(const pt::ptree &tree);
|
void parse_rss(const pt::ptree &tree);
|
||||||
[[nodiscard]] string remove_html(string html) const;
|
[[nodiscard]] static string remove_html(string html);
|
||||||
[[nodiscard]] static string
|
[[nodiscard]] static string
|
||||||
extract_location(const curl_wrapper::answer &answer);
|
extract_location(const curl_wrapper::answer &answer);
|
||||||
string add_hashtags(const string &text);
|
string add_hashtags(const string &text);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
#include "curl_wrapper.hpp"
|
||||||
#include "document.hpp"
|
#include "document.hpp"
|
||||||
#include "exceptions.hpp"
|
#include "exceptions.hpp"
|
||||||
#include "mastoapi.hpp"
|
#include "mastoapi.hpp"
|
||||||
|
@ -71,7 +72,8 @@ void print_version()
|
||||||
|
|
||||||
void print_help(const string_view command)
|
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)
|
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';
|
cerr << e.what() << '\n';
|
||||||
return error::network;
|
return error::network;
|
||||||
}
|
}
|
||||||
|
catch (const curl_wrapper::CURLException &e)
|
||||||
|
{
|
||||||
|
cerr << e.what() << '\n';
|
||||||
|
return error::network;
|
||||||
|
}
|
||||||
catch (const Json::RuntimeError &e)
|
catch (const Json::RuntimeError &e)
|
||||||
{
|
{
|
||||||
cerr << "JSON error:\n" << e.what() << '\n';
|
cerr << "JSON error:\n" << e.what() << '\n';
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* This file is part of mastorss.
|
/* 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
|
* 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
|
||||||
|
@ -124,6 +124,8 @@ void MastoAPI::post_item(const Item &item, bool dry_run)
|
||||||
{
|
{
|
||||||
if (ret.http_status != 200)
|
if (ret.http_status != 200)
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "Error message from server: "
|
||||||
|
<< ret.body;
|
||||||
throw HTTPException{ret.http_status};
|
throw HTTPException{ret.http_status};
|
||||||
}
|
}
|
||||||
throw CURLException{ret.curl_error_code};
|
throw CURLException{ret.curl_error_code};
|
||||||
|
|
Loading…
Reference in New Issue