Erste fortschritte.
This commit is contained in:
parent
f991a74f3c
commit
368cd91bf3
|
@ -7,6 +7,8 @@ include(GNUInstallDirs)
|
|||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(LIBXDG_BASEDIR REQUIRED libxdg-basedir)
|
||||
pkg_check_modules(LIBCONFIG REQUIRED libconfig++)
|
||||
pkg_check_modules(CURLPP REQUIRED curlpp)
|
||||
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
@ -18,12 +20,19 @@ set(CMAKE_CXX_FLAGS_DEBUG
|
|||
include_directories(${PROJECT_BINARY_DIR})
|
||||
include_directories(${LIBXDG_BASEDIR_INCLUDE_DIRS})
|
||||
include_directories(${LIBCONFIG_INCLUDE_DIRS})
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
include_directories(${CURLPP_INCLUDE_DIRS})
|
||||
include_directories(${JSONCPP_INCLUDE_DIRS})
|
||||
|
||||
link_directories(${LIBXDG_BASEDIR_LIBRARY_DIRS})
|
||||
link_directories(${LIBCONFIG_LIBRARY_DIRS})
|
||||
link_directories(${CURL_LIBRARY_DIRS})
|
||||
link_directories(${CURLPP_LIBRARY_DIRS})
|
||||
link_directories(${JSONCPP_LIBRARY_DIRS})
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME} feiertagebot.cpp)
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
"${LIBXDG_BASEDIR_LDFLAGS} ${LIBCONFIG_LDFLAGS}"
|
||||
"${CURLPP_LDFLAGS} ${JSONCPP_LDFLAGS}"
|
||||
"-lstdc++fs")
|
||||
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
|
19
README.adoc
19
README.adoc
|
@ -1,19 +1,16 @@
|
|||
= feiertagebot
|
||||
|
||||
*feiertagebot* ist ein Mastodon-bot, der über anstehende feiertage in
|
||||
Deutschland informiert. Die daten stammen von
|
||||
https://github.com/wlbr/feiertage.
|
||||
Deutschland informiert. Die daten stammen von https://feiertage-api.de/.
|
||||
|
||||
== Installation und benutzung
|
||||
== Dependencies
|
||||
|
||||
[source,shell]
|
||||
----
|
||||
wget https://schlomp.space/tastytea/feiertagebot/raw/branch/master/feiertagebot
|
||||
chmod +x feiertagebot
|
||||
echo "token=<your token here>" > ~/.config/feiertagebot.cfg
|
||||
echo "instance=social.example.com" >> ~/.config/feiertagebot.cfg
|
||||
./feiertagebot
|
||||
----
|
||||
* C++ compiler
|
||||
* [cmake](https://cmake.org/) (at least 3.2)
|
||||
* [libxdg-basedir](http://repo.or.cz/w/libxdg-basedir.git) (tested: 1.2)
|
||||
* [libconfig++](https://github.com/hyperrealm/libconfig) (tested: 1.5)
|
||||
* [curlpp](http://www.curlpp.org/) (tested: 0.8)
|
||||
* [jsoncpp](https://github.com/open-source-parsers/jsoncpp) (tested: 1.8)
|
||||
|
||||
== Lizenz
|
||||
|
||||
|
|
|
@ -1,8 +1,56 @@
|
|||
// Author: tastytea <tastytea@tastytea.de>
|
||||
// CC-0 / Public Domain
|
||||
// Version: 2019-02-11_1
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <curlpp/Options.hpp>
|
||||
#include <curlpp/Exception.hpp>
|
||||
#include <curlpp/Infos.hpp>
|
||||
#include <json/json.h>
|
||||
|
||||
namespace curlopts = curlpp::options;
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
int main()
|
||||
{
|
||||
const string version = "2019-02-11_1";
|
||||
|
||||
try
|
||||
{
|
||||
string year = "2019";
|
||||
string today = "2019-12-25";
|
||||
string tomorrow = "2019-12-26";
|
||||
curlpp::Easy request;
|
||||
std::stringstream ss;
|
||||
|
||||
request.setOpt<curlopts::Url>("https://feiertage-api.de/api/?jahr=" + year);
|
||||
request.setOpt<curlopts::UserAgent>("feiertagebot/" + version);
|
||||
request.setOpt<curlopts::FollowLocation>(true);
|
||||
ss << request;
|
||||
|
||||
Json::Value root;
|
||||
ss >> root;
|
||||
|
||||
for (Json::Value::const_iterator it_root = root.begin(); it_root != root.end(); ++it_root)
|
||||
{
|
||||
for (Json::Value::const_iterator it_region = it_root->begin(); it_region != it_root->end(); ++it_region)
|
||||
{
|
||||
if ((*it_region)["datum"] == today)
|
||||
{
|
||||
cout << it_root.key() << ": " << (*it_region)["datum"] << ": " << it_region.key() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
cerr << e.what() << endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue