Alerts in cron mode atre working
This commit is contained in:
parent
dbbc9cea96
commit
c3858936d0
|
@ -1,6 +1,6 @@
|
||||||
cmake_minimum_required (VERSION 3.7)
|
cmake_minimum_required (VERSION 3.7)
|
||||||
project (mastobotmon
|
project (mastobotmon
|
||||||
VERSION 0.0.3
|
VERSION 0.1.0
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,11 @@ If you use a debug build, you get more verbose error messages.
|
||||||
# TODO
|
# TODO
|
||||||
|
|
||||||
* Version 0.1.0
|
* Version 0.1.0
|
||||||
* [ ] Cron mode
|
* [x] Cron mode
|
||||||
* [x] Config file
|
* [x] Config file
|
||||||
* [ ] Alert if account seems inactive
|
* [x] Alert if account seems inactive
|
||||||
* Version 0.2.0
|
* Version 0.2.0
|
||||||
|
* [ ] Allow to add accounts later
|
||||||
* [ ] Write mentions to file
|
* [ ] Write mentions to file
|
||||||
* Version 0.3.0
|
* Version 0.3.0
|
||||||
* [ ] Write statistics to file
|
* [ ] Write statistics to file
|
||||||
|
|
|
@ -18,6 +18,10 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iomanip> // get_time
|
||||||
#include <rapidjson/document.h>
|
#include <rapidjson/document.h>
|
||||||
#include "version.hpp"
|
#include "version.hpp"
|
||||||
#include "mastobotmon.hpp"
|
#include "mastobotmon.hpp"
|
||||||
|
@ -26,6 +30,7 @@ using std::cout;
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
using std::cin;
|
using std::cin;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::uint16_t;
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -69,8 +74,21 @@ int main(int argc, char *argv[])
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
{
|
{
|
||||||
json.Parse(answer.c_str());
|
json.Parse(answer.c_str());
|
||||||
cout << "The last toot of " << json[0]["account"]["acct"].GetString()
|
const string acct = json[0]["account"]["acct"].GetString();
|
||||||
<< " was at " << json[0]["created_at"].GetString() << ".\n";
|
|
||||||
|
std::istringstream isslast(json[0]["created_at"].GetString());
|
||||||
|
struct std::tm tm = {0};
|
||||||
|
isslast >> std::get_time(&tm, "%Y-%m-%dT%T");
|
||||||
|
std::time_t time = mktime(&tm);
|
||||||
|
|
||||||
|
const auto now = std::chrono::system_clock::now();
|
||||||
|
const auto last = std::chrono::system_clock::from_time_t(time);
|
||||||
|
auto elapsed = std::chrono::duration_cast<std::chrono::minutes>(now - last);
|
||||||
|
|
||||||
|
if (elapsed.count() > acc.get_minutes())
|
||||||
|
{
|
||||||
|
cout << "ALERT: " << acct << " is inactive since " << elapsed.count() << " minutes.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ class Account : public Mastodon::API
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit Account(const string &instance, const string &access_token);
|
explicit Account(const string &instance, const string &access_token);
|
||||||
void set_minutes(uint16_t minutes);
|
const void set_minutes(uint16_t minutes);
|
||||||
|
const uint16_t get_minutes() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t _minutes;
|
uint16_t _minutes;
|
||||||
|
|
|
@ -34,7 +34,12 @@ Account::Account(const string &instance, const string &access_token)
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void Account::set_minutes(uint16_t minutes)
|
const void Account::set_minutes(uint16_t minutes)
|
||||||
{
|
{
|
||||||
_minutes = minutes;
|
_minutes = minutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint16_t Account::get_minutes() const
|
||||||
|
{
|
||||||
|
return _minutes;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user