feiertagebot/feiertagebot.cpp

57 lines
1.4 KiB
C++
Raw Normal View History

2019-02-11 19:15:37 +01:00
// Author: tastytea <tastytea@tastytea.de>
// CC-0 / Public Domain
2019-02-11 21:32:44 +01:00
#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;
2019-02-11 19:15:37 +01:00
int main()
{
2019-02-11 21:32:44 +01:00
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;
}
2019-02-11 19:15:37 +01:00
return 0;
}