rename rss2mastodon -> mastorss
This commit is contained in:
parent
bf6c5df56f
commit
f0c6004f30
|
@ -1,17 +1,26 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
project (rss2mastodon
|
project (mastorss
|
||||||
VERSION 0.2.0
|
VERSION 0.2.1
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
set(CMAKE_CXX_STANDARD 14)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
include_directories(${MY_SOURCE_DIR}/src)
|
||||||
|
include_directories(${PROJECT_BINARY_DIR})
|
||||||
|
|
||||||
|
# Write version in header
|
||||||
|
configure_file (
|
||||||
|
"${PROJECT_SOURCE_DIR}/src/version.hpp.in"
|
||||||
|
"${PROJECT_BINARY_DIR}/version.hpp"
|
||||||
|
)
|
||||||
|
|
||||||
include(FindCURL)
|
include(FindCURL)
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
|
|
||||||
add_executable(rss2mastodon src/rss2mastodon.cpp src/http.cpp)
|
add_executable(mastorss src/mastorss.cpp src/http.cpp)
|
||||||
target_link_libraries(rss2mastodon mastodon-cpp boost_system boost_filesystem ssl crypto ${CURL_LIBRARIES} curlpp)
|
target_link_libraries(mastorss mastodon-cpp boost_system boost_filesystem ssl crypto ${CURL_LIBRARIES} curlpp)
|
||||||
install(TARGETS rss2mastodon DESTINATION ${CMAKE_INSTALL_BINDIR})
|
install(TARGETS mastorss DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
**rss2mastodon** dumps RSS feeds into a mastodon account.
|
**mastorss** dumps RSS feeds into a mastodon account.
|
||||||
It is hacked together and generally only extended/fixed when it fails.
|
It is hacked together and generally only extended/fixed when it fails.
|
||||||
Use at your own risk.
|
Use at your own risk.
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ Install with `make install`.
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
|
||||||
Put watchwords.json into `~/.config/rss2mastodon/`. Launch with profile name.
|
Put watchwords.json into `~/.config/mastorss/`. Launch with profile name.
|
||||||
In the first run only the newest entry is tooted.
|
In the first run only the newest entry is tooted.
|
||||||
|
|
||||||
The profile can't be named "global".
|
The profile can't be named "global".
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* This file is part of rss2mastodon.
|
/* This file is part of mastorss.
|
||||||
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
* Copyright © 2018 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
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
#include <curlpp/Easy.hpp>
|
#include <curlpp/Easy.hpp>
|
||||||
#include <curlpp/Options.hpp>
|
#include <curlpp/Options.hpp>
|
||||||
#include <curlpp/Exception.hpp>
|
#include <curlpp/Exception.hpp>
|
||||||
#include "rss2mastodon.hpp"
|
#include "mastorss.hpp"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
@ -44,6 +44,7 @@ const std::uint16_t http_get(const string &feedurl, string &answer, const string
|
||||||
"Connection: close",
|
"Connection: close",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
oss << request;
|
oss << request;
|
||||||
answer = oss.str();
|
answer = oss.str();
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* This file is part of rss2mastodon.
|
/* This file is part of mastorss.
|
||||||
* Copyright © 2018 tastytea <tastytea@tastytea.de>
|
* Copyright © 2018 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
|
||||||
|
@ -29,18 +29,20 @@
|
||||||
#include <boost/property_tree/xml_parser.hpp>
|
#include <boost/property_tree/xml_parser.hpp>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <mastodon-cpp.hpp>
|
#include <mastodon-cpp.hpp>
|
||||||
#include "rss2mastodon.hpp"
|
#include "version.hpp"
|
||||||
|
#include "mastorss.hpp"
|
||||||
|
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
using Mastodon::API;
|
using Mastodon::API;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
using std::cin;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
std::uint16_t max_size = 500;
|
std::uint16_t max_size = 500;
|
||||||
const string filepath = string(getenv("HOME")) + "/.config/rss2mastodon/";
|
const string filepath = string(getenv("HOME")) + "/.config/mastorss/";
|
||||||
|
|
||||||
void read_config(pt::ptree &config, const string &profile, string &instance, string &access_token, string &feedurl)
|
std::uint16_t read_config(pt::ptree &config, const string &profile, string &instance, string &access_token, string &feedurl)
|
||||||
{
|
{
|
||||||
bool config_changed = false;
|
bool config_changed = false;
|
||||||
|
|
||||||
|
@ -62,21 +64,58 @@ void read_config(pt::ptree &config, const string &profile, string &instance, str
|
||||||
if (instance.empty())
|
if (instance.empty())
|
||||||
{
|
{
|
||||||
cout << "Instance: ";
|
cout << "Instance: ";
|
||||||
std::cin >> instance;
|
cin >> instance;
|
||||||
config.put(profile + ".instance", instance);
|
config.put(profile + ".instance", instance);
|
||||||
config_changed = true;
|
config_changed = true;
|
||||||
}
|
}
|
||||||
if (access_token.empty())
|
if (access_token.empty())
|
||||||
{
|
{
|
||||||
cout << "access_token: ";
|
cout << "No access token found.\n";
|
||||||
std::cin >> access_token;
|
string client_id, client_secret, url;
|
||||||
config.put(profile + ".access_token", access_token);
|
Mastodon::API masto(instance, "");
|
||||||
config_changed = true;
|
std::uint16_t ret = masto.register_app1(instance,
|
||||||
|
"mastorss",
|
||||||
|
"urn:ietf:wg:oauth:2.0:oob",
|
||||||
|
"write",
|
||||||
|
"",
|
||||||
|
client_id,
|
||||||
|
client_secret,
|
||||||
|
url);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
string code;
|
||||||
|
cout << "Visit " << url << " to authorize this application.\n";
|
||||||
|
cout << "Insert code: ";
|
||||||
|
cin >> code;
|
||||||
|
|
||||||
|
masto.register_app2(instance,
|
||||||
|
client_id,
|
||||||
|
client_secret,
|
||||||
|
"urn:ietf:wg:oauth:2.0:oob",
|
||||||
|
code,
|
||||||
|
access_token);
|
||||||
|
if (ret == 0)
|
||||||
|
{
|
||||||
|
config.put(profile + ".access_token", access_token);
|
||||||
|
config_changed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cerr << "Error code: " << ret << '\n';
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cerr << "Error code: " << ret << '\n';
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (feedurl.empty())
|
if (feedurl.empty())
|
||||||
{
|
{
|
||||||
cout << "feedurl: ";
|
cout << "feedurl: ";
|
||||||
std::cin >> feedurl;
|
cin >> feedurl;
|
||||||
config.put(profile + ".feedurl", feedurl);
|
config.put(profile + ".feedurl", feedurl);
|
||||||
config_changed = true;
|
config_changed = true;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +123,8 @@ void read_config(pt::ptree &config, const string &profile, string &instance, str
|
||||||
{
|
{
|
||||||
pt::write_json(filepath + "config-" + profile + ".json", config);
|
pt::write_json(filepath + "config-" + profile + ".json", config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<string> parse_website(const string &profile, const string &xml)
|
std::vector<string> parse_website(const string &profile, const string &xml)
|
||||||
|
@ -206,7 +247,7 @@ int main(int argc, char *argv[])
|
||||||
string last_entry = config.get(profile + ".last_entry", "");
|
string last_entry = config.get(profile + ".last_entry", "");
|
||||||
std::vector<string> entries;
|
std::vector<string> entries;
|
||||||
//FIXME: User-Agent
|
//FIXME: User-Agent
|
||||||
ret = http_get(feedurl, answer, "rss2mastodon/experimental");
|
ret = http_get(feedurl, answer, "mastorss/" + (string)global::version);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
return ret;
|
return ret;
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef RSS2MASTODON_HPP
|
#ifndef mastorss_HPP
|
||||||
#define RSS2MASTODON_HPP
|
#define mastorss_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -9,11 +9,11 @@
|
||||||
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, string &feedurl);
|
std::uint16_t 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
|
||||||
const std::uint16_t http_get(const string &feedurl,
|
const std::uint16_t http_get(const string &feedurl,
|
||||||
string &answer, const string &useragent = "");
|
string &answer, const string &useragent = "");
|
||||||
|
|
||||||
#endif // RSS2MASTODON_HPP
|
#endif // mastorss_HPP
|
9
src/version.hpp.in
Normal file
9
src/version.hpp.in
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef VERSION_HPP
|
||||||
|
#define VERSION_HPP
|
||||||
|
|
||||||
|
namespace global
|
||||||
|
{
|
||||||
|
static constexpr char version[] = "@PROJECT_VERSION@";
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // VERSION_HPP
|
Loading…
Reference in New Issue
Block a user