Fixed account storing, print time of last toot.

This commit is contained in:
tastytea 2018-02-28 22:16:56 +01:00
parent 0f84c4f123
commit 4030c88ccf
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
6 changed files with 32 additions and 19 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (mastobotmon
VERSION 0.0.2
VERSION 0.0.3
LANGUAGES CXX
)

View File

@ -38,7 +38,7 @@ Call mastobotmon from cron.
* Version 0.1.0
* [ ] Cron mode
* [ ] Config file
* [x] Config file
* [ ] Alert if account seems inactive
* Version 0.2.0
* [ ] Write mentions to file

View File

@ -128,6 +128,7 @@ const string get_access_token(const string &account)
{
const string instance = account.substr(account.find('@') + 1);
Account acc(instance, "");
acc.set_useragent("mastobotmon/" + string(global::version));
uint16_t ret;
string client_id;
string client_secret;

View File

@ -39,31 +39,45 @@ int main(int argc, char *argv[])
for (const auto &member : document["accounts"].GetObject())
{
// Construct an Account object for every account
// Construct an Account object for every account and store it in a vector
string instance = member.name.GetString();
instance = instance.substr(instance.find('@') + 1);
Account acc(instance, member.value["access_token"].GetString());
acc.set_minutes(member.value["minutes"].GetUint());
accounts.push_back(acc);
Account *acc = new Account(instance, member.value["access_token"].GetString());
acc->set_useragent("mastobotmon/" + string(global::version));
acc->set_minutes(member.value["minutes"].GetUint());
accounts.push_back(*acc);
}
cout << "DEBUG\n";
if (document["mode"] == "cron")
{
cout << "DEBUG\n";
for (Account &acc : accounts)
{
cout << "DEBUG\n";
std::string answer;
// std::string id;
uint16_t ret = acc.get(Mastodon::API::v1::accounts_verify_credentials, answer);
if (ret == 0)
{
rapidjson::Document json;
json.Parse(answer.c_str());
const string id = json["id"].GetString();
// Account::parametermap parameters(
// {
// { "limit", { "1" } }
// });
// cout << acc.get(Mastodon::API::v1::statuses, id, parameters, answer);
cout << acc.get(Mastodon::API::v1::accounts_verify_credentials, answer);
cout << answer << '\n';
Account::parametermap parameters(
{
{ "limit", { "1" } }
});
ret = acc.get(Mastodon::API::v1::accounts_id_statuses, id, parameters, answer);
if (ret == 0)
{
json.Parse(answer.c_str());
cout << "The last toot of " << json[0]["account"]["acct"].GetString()
<< " was at " << json[0]["created_at"].GetString() << ".\n";
}
}
if (ret != 0)
{
cerr << "Error: " << ret << '\n';
}
}
}

View File

@ -36,7 +36,6 @@ public:
private:
uint16_t _minutes;
string _access_token;
};
#endif // mastobotmon_HPP

View File

@ -30,7 +30,6 @@ using std::uint16_t;
Account::Account(const string &instance, const string &access_token)
: API(instance, access_token)
, _minutes(0)
, _access_token("")
{
//
}