From 12678160ad46a37f080b16131e1d32137af23406 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 18 Apr 2019 07:11:55 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=BCfe,=20ob=20morgen=20oder=20=C3=BCbermor?= =?UTF-8?q?gen=20ein=20feiertag=20ist.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vorher: Heute oder morgen. --- README.adoc | 4 ++-- feiertagebot.cpp | 26 +++++++++++++++++--------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.adoc b/README.adoc index 2d8a038..f14c32f 100644 --- a/README.adoc +++ b/README.adoc @@ -2,8 +2,8 @@ *feiertagebot* ist ein Mastodon-bot, der über anstehende feiertage in Deutschland informiert. Die daten stammen von https://feiertage-api.de/. Nach -dem aufruf wird überprüft, ob heute oder morgen ein gesetzlicher feiertag ist. -Wenn ja, wird ein post abgesetzt. Der bot läuft als +dem aufruf wird überprüft, ob morgen oder übermorgen ein gesetzlicher +feiertag ist. Wenn ja, wird ein post abgesetzt. Der bot läuft als https://botsin.space/@feiertage_de[@feiertage_de@botsin.space]. == Installation diff --git a/feiertagebot.cpp b/feiertagebot.cpp index b373acd..dcab8a5 100644 --- a/feiertagebot.cpp +++ b/feiertagebot.cpp @@ -28,7 +28,7 @@ using std::chrono::system_clock; using std::chrono::hours; using std::uint_fast16_t; -const string version = "2019-02-12_4"; +const string version = "2019-04-18_1"; struct Holiday { @@ -69,7 +69,8 @@ const string decode_state(const string &abbr) } } -const string get_date(const system_clock::time_point &timepoint, const string &format) +const string get_date(const system_clock::time_point &timepoint, + const string &format) { std::time_t time = system_clock::to_time_t(timepoint); std::tm *timeinfo = std::localtime(&time); @@ -144,13 +145,15 @@ int main() try { string year = get_date(system_clock::now(), "%Y"); - string today = get_date(system_clock::now(), "%d.%m.%Y"); string tomorrow = get_date(system_clock::now() + hours(24), "%d.%m.%Y"); + string overmorrow = get_date(system_clock::now() + hours(48), + "%d.%m.%Y"); curlpp::Easy request; std::stringstream ss; - request.setOpt("https://feiertage-api.de/api/?jahr=" + year); + request.setOpt("https://feiertage-api.de/api/?jahr=" + + year); request.setOpt("feiertagebot/" + version); request.setOpt(true); ss << request; @@ -159,12 +162,14 @@ int main() string output; - for (const string &date : { today, tomorrow }) + for (const string &date : { tomorrow, overmorrow }) { Holiday current_day; - for (Json::Value::const_iterator it_root = root.begin(); it_root != root.end(); ++it_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) + for (Json::Value::const_iterator it_region = it_root->begin(); + it_region != it_root->end(); ++it_region) { if ((*it_region)["datum"] == date) { @@ -178,8 +183,11 @@ int main() { continue; } - output += "Am " + current_day.date + " ist " + current_day.description + ", ein gesetzlicher Feiertag in "; - if (std::find(current_day.regions.begin(), current_day.regions.end(), "NATIONAL") != current_day.regions.end()) + output += "Am " + current_day.date + " ist " + + current_day.description + ", ein gesetzlicher Feiertag in "; + if (std::find(current_day.regions.begin(), + current_day.regions.end(), "NATIONAL") + != current_day.regions.end()) { output += "Deutschland.\n"; }