rename rss2mastodon -> mastorss

This commit is contained in:
tastytea 2018-02-10 12:35:06 +01:00
parent bf6c5df56f
commit f0c6004f30
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
6 changed files with 84 additions and 24 deletions

View File

@ -1,17 +1,26 @@
cmake_minimum_required (VERSION 3.7)
include(GNUInstallDirs)
project (rss2mastodon
VERSION 0.2.0
project (mastorss
VERSION 0.2.1
LANGUAGES CXX
)
set(CMAKE_CXX_STANDARD 14)
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)
find_package(CURL REQUIRED)
add_executable(rss2mastodon src/rss2mastodon.cpp src/http.cpp)
target_link_libraries(rss2mastodon mastodon-cpp boost_system boost_filesystem ssl crypto ${CURL_LIBRARIES} curlpp)
install(TARGETS rss2mastodon DESTINATION ${CMAKE_INSTALL_BINDIR})
add_executable(mastorss src/mastorss.cpp src/http.cpp)
target_link_libraries(mastorss mastodon-cpp boost_system boost_filesystem ssl crypto ${CURL_LIBRARIES} curlpp)
install(TARGETS mastorss DESTINATION ${CMAKE_INSTALL_BINDIR})

View File

@ -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.
Use at your own risk.
@ -35,7 +35,7 @@ Install with `make install`.
# 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.
The profile can't be named "global".

View File

@ -1,4 +1,4 @@
/* This file is part of rss2mastodon.
/* This file is part of mastorss.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* This program is free software: you can redistribute it and/or modify
@ -24,7 +24,7 @@
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>
#include "rss2mastodon.hpp"
#include "mastorss.hpp"
using std::string;
using std::cerr;
@ -44,6 +44,7 @@ const std::uint16_t http_get(const string &feedurl, string &answer, const string
"Connection: close",
});
oss << request;
answer = oss.str();

View File

@ -1,4 +1,4 @@
/* This file is part of rss2mastodon.
/* This file is part of mastorss.
* Copyright © 2018 tastytea <tastytea@tastytea.de>
*
* 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/filesystem.hpp>
#include <mastodon-cpp.hpp>
#include "rss2mastodon.hpp"
#include "version.hpp"
#include "mastorss.hpp"
namespace pt = boost::property_tree;
using Mastodon::API;
using std::cout;
using std::cerr;
using std::cin;
using std::string;
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;
@ -62,21 +64,58 @@ void read_config(pt::ptree &config, const string &profile, string &instance, str
if (instance.empty())
{
cout << "Instance: ";
std::cin >> instance;
cin >> instance;
config.put(profile + ".instance", instance);
config_changed = true;
}
if (access_token.empty())
{
cout << "access_token: ";
std::cin >> access_token;
config.put(profile + ".access_token", access_token);
config_changed = true;
cout << "No access token found.\n";
string client_id, client_secret, url;
Mastodon::API masto(instance, "");
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())
{
cout << "feedurl: ";
std::cin >> feedurl;
cin >> feedurl;
config.put(profile + ".feedurl", feedurl);
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);
}
return 0;
}
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", "");
std::vector<string> entries;
//FIXME: User-Agent
ret = http_get(feedurl, answer, "rss2mastodon/experimental");
ret = http_get(feedurl, answer, "mastorss/" + (string)global::version);
if (ret != 0)
{
return ret;

View File

@ -1,5 +1,5 @@
#ifndef RSS2MASTODON_HPP
#define RSS2MASTODON_HPP
#ifndef mastorss_HPP
#define mastorss_HPP
#include <cstdint>
#include <string>
@ -9,11 +9,11 @@
namespace pt = boost::property_tree;
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);
// http.cpp
const std::uint16_t http_get(const string &feedurl,
string &answer, const string &useragent = "");
#endif // RSS2MASTODON_HPP
#endif // mastorss_HPP

9
src/version.hpp.in Normal file
View File

@ -0,0 +1,9 @@
#ifndef VERSION_HPP
#define VERSION_HPP
namespace global
{
static constexpr char version[] = "@PROJECT_VERSION@";
}
#endif // VERSION_HPP