Prüfe, ob morgen oder übermorgen ein feiertag ist.

Vorher: Heute oder morgen.
This commit is contained in:
tastytea 2019-04-18 07:11:55 +02:00
parent f44f6b0e47
commit 12678160ad
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 19 additions and 11 deletions

View File

@ -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

View File

@ -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<curlopts::Url>("https://feiertage-api.de/api/?jahr=" + year);
request.setOpt<curlopts::Url>("https://feiertage-api.de/api/?jahr="
+ year);
request.setOpt<curlopts::UserAgent>("feiertagebot/" + version);
request.setOpt<curlopts::FollowLocation>(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";
}