A bit of clean-up.
This commit is contained in:
parent
73aa20a193
commit
b56d39c0c2
|
@ -1,8 +1,16 @@
|
||||||
// Author: tastytea <tastytea@tastytea.de>
|
// Author: tastytea <tastytea@tastytea.de>
|
||||||
// CC-0 / Public Domain
|
// CC-0 / Public Domain
|
||||||
|
|
||||||
#include <mastodonpp/instance.hpp>
|
#include "xdgjson/src/xdgjson.hpp"
|
||||||
|
|
||||||
|
#include <mastodonpp/mastodonpp.hpp>
|
||||||
|
#include <curlpp/Options.hpp>
|
||||||
|
#include <curlpp/Exception.hpp>
|
||||||
|
#include <curlpp/Infos.hpp>
|
||||||
|
#include <json/json.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -12,12 +20,6 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <curlpp/Options.hpp>
|
|
||||||
#include <curlpp/Exception.hpp>
|
|
||||||
#include <curlpp/Infos.hpp>
|
|
||||||
#include <json/json.h>
|
|
||||||
#include <mastodonpp/mastodonpp.hpp>
|
|
||||||
#include "xdgjson/src/xdgjson.hpp"
|
|
||||||
|
|
||||||
namespace curlopts = curlpp::options;
|
namespace curlopts = curlpp::options;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -27,18 +29,18 @@ using std::endl;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
using std::chrono::system_clock;
|
using std::chrono::system_clock;
|
||||||
using std::chrono::hours;
|
using std::chrono::hours;
|
||||||
using std::uint_fast16_t;
|
using std::string_view;
|
||||||
|
|
||||||
const string version = "2020-05-16_1";
|
constexpr string_view version = "2020-05-16_1";
|
||||||
|
|
||||||
struct Holiday
|
struct holiday
|
||||||
{
|
{
|
||||||
string date;
|
string date;
|
||||||
string description;
|
string description;
|
||||||
vector<string> regions;
|
vector<string> regions;
|
||||||
};
|
};
|
||||||
|
|
||||||
const string decode_state(const string &abbr)
|
string decode_state(const string &abbr)
|
||||||
{
|
{
|
||||||
const std::map<string, string> states =
|
const std::map<string, string> states =
|
||||||
{
|
{
|
||||||
|
@ -64,13 +66,11 @@ const string decode_state(const string &abbr)
|
||||||
{
|
{
|
||||||
return states.find(abbr)->second;
|
return states.find(abbr)->second;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return abbr;
|
return abbr;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const string get_date(const system_clock::time_point &timepoint,
|
string get_date(const system_clock::time_point &timepoint,
|
||||||
const string &format)
|
const string &format)
|
||||||
{
|
{
|
||||||
std::time_t time = system_clock::to_time_t(timepoint);
|
std::time_t time = system_clock::to_time_t(timepoint);
|
||||||
|
@ -80,7 +80,7 @@ const string get_date(const system_clock::time_point &timepoint,
|
||||||
return string(buffer);
|
return string(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
const string get_token(const string &instance)
|
string get_token(const string &instance)
|
||||||
{
|
{
|
||||||
mastodonpp::Instance server{instance, ""};
|
mastodonpp::Instance server{instance, ""};
|
||||||
mastodonpp::Instance::ObtainToken token{server};
|
mastodonpp::Instance::ObtainToken token{server};
|
||||||
|
@ -110,7 +110,8 @@ const string get_token(const string &instance)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
string instance, access_token;
|
string instance;
|
||||||
|
string access_token;
|
||||||
xdgjson config("feiertagebot.json");
|
xdgjson config("feiertagebot.json");
|
||||||
config.read();
|
config.read();
|
||||||
Json::Value &json = config.get_json();
|
Json::Value &json = config.get_json();
|
||||||
|
@ -147,7 +148,7 @@ int main()
|
||||||
|
|
||||||
request.setOpt<curlopts::Url>("https://feiertage-api.de/api/?jahr="
|
request.setOpt<curlopts::Url>("https://feiertage-api.de/api/?jahr="
|
||||||
+ year);
|
+ year);
|
||||||
request.setOpt<curlopts::UserAgent>("feiertagebot/" + version);
|
request.setOpt<curlopts::UserAgent>(string("feiertagebot/") += version);
|
||||||
request.setOpt<curlopts::FollowLocation>(true);
|
request.setOpt<curlopts::FollowLocation>(true);
|
||||||
ss << request;
|
ss << request;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
|
@ -157,7 +158,7 @@ int main()
|
||||||
|
|
||||||
for (const string &date : { tomorrow, overmorrow })
|
for (const string &date : { tomorrow, overmorrow })
|
||||||
{
|
{
|
||||||
Holiday current_day;
|
holiday current_day;
|
||||||
for (Json::Value::const_iterator it_root = root.begin();
|
for (Json::Value::const_iterator it_root = root.begin();
|
||||||
it_root != root.end(); ++it_root)
|
it_root != root.end(); ++it_root)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue