From 368cd91bf3abf0d11af091f39c472c8110569ccb Mon Sep 17 00:00:00 2001 From: tastytea Date: Mon, 11 Feb 2019 21:32:44 +0100 Subject: [PATCH] Erste fortschritte. --- CMakeLists.txt | 9 +++++++++ README.adoc | 19 ++++++++---------- feiertagebot.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 753e0e2..7094cab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/README.adoc b/README.adoc index 3237d7b..9a24147 100644 --- a/README.adoc +++ b/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=" > ~/.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 diff --git a/feiertagebot.cpp b/feiertagebot.cpp index adc1410..d38bb0b 100644 --- a/feiertagebot.cpp +++ b/feiertagebot.cpp @@ -1,8 +1,56 @@ // Author: tastytea // CC-0 / Public Domain -// Version: 2019-02-11_1 + +#include +#include +#include +#include +#include +#include +#include +#include + +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("https://feiertage-api.de/api/?jahr=" + year); + request.setOpt("feiertagebot/" + version); + request.setOpt(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; }