Added statistics
This commit is contained in:
parent
756e71cf5a
commit
24719bec13
|
@ -1,6 +1,6 @@
|
|||
cmake_minimum_required (VERSION 3.7)
|
||||
project (mastobotmon
|
||||
VERSION 0.2.2
|
||||
VERSION 0.3.0
|
||||
LANGUAGES CXX)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
|
|
@ -75,6 +75,10 @@ If you use a debug build, you get more verbose error messages.
|
|||
|
||||
Mentions are written to `data_dir/mentions_account.csv`. The format is: acct;created_at;content.
|
||||
|
||||
## Statistics
|
||||
|
||||
Statistics are written to `data_dir/statistics_account.csv`. The format is: time;toots;followers.
|
||||
|
||||
# TODO
|
||||
|
||||
* Version 0.1.0
|
||||
|
@ -86,7 +90,7 @@ Mentions are written to `data_dir/mentions_account.csv`. The format is: acct;cre
|
|||
* [x] Write mentions to file
|
||||
* Version 0.3.0
|
||||
* [x] Respect X-RateLimit header
|
||||
* [ ] Write statistics to file
|
||||
* [x] Write statistics to file
|
||||
* Version 0.4.0
|
||||
* [ ] Daemon mode
|
||||
* Version 0.5.0
|
||||
|
|
|
@ -64,6 +64,33 @@ const bool write_mentions(const string &straccount, Json::Value &mentions)
|
|||
return false;
|
||||
}
|
||||
|
||||
const bool write_statistics(const string &straccount, Json::Value &account_json)
|
||||
{
|
||||
const string filepath = config["data_dir"].asString() + "/statistics_" + straccount + ".csv";
|
||||
|
||||
std::ofstream outfile(filepath, std::ios::app);
|
||||
if (outfile.is_open())
|
||||
{
|
||||
string output;
|
||||
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
|
||||
std::time_t now_t = std::chrono::system_clock::to_time_t(now);
|
||||
std::tm now_tm = *std::localtime(&now_t);
|
||||
std::stringstream ss;
|
||||
|
||||
ss << std::put_time(&now_tm, "%Y-%m-%dT%T");
|
||||
output = ss.str() + ';';
|
||||
output += account_json["statuses_count"].asString() + ';';
|
||||
output += account_json["followers_count"].asString() + ";\n";
|
||||
outfile.write(output.c_str(), output.length());
|
||||
outfile.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
cerr << "Error writing file: " << filepath << '\n';
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint16_t mainret = 0;
|
||||
|
@ -116,6 +143,8 @@ int main(int argc, char *argv[])
|
|||
Json::Reader reader;
|
||||
reader.parse(answer, json);
|
||||
const string id = json["id"].asString();
|
||||
const string straccount = json["account"]["acct"].asString() + "@" + acc.get_instance();
|
||||
write_statistics(straccount, json);
|
||||
|
||||
Account::parametermap parameters(
|
||||
{
|
||||
|
@ -170,7 +199,6 @@ int main(int argc, char *argv[])
|
|||
if (!json.empty())
|
||||
{
|
||||
const std::uint64_t lastid = std::stoull(json[0]["id"].asString());
|
||||
const string straccount = acct + "@" + acc.get_instance();
|
||||
acc.set_last_mention_id(lastid);
|
||||
config["accounts"][straccount]["last_mention"] = lastid;
|
||||
write_mentions(straccount, json);
|
||||
|
|
|
@ -47,5 +47,6 @@ const bool add_account();
|
|||
const bool write_config();
|
||||
|
||||
const bool write_mentions(const string &straccount, Json::Value &mentions);
|
||||
const bool write_statistics(const string &straccount, Json::Value &account_json);
|
||||
|
||||
#endif // mastobotmon_HPP
|
||||
|
|
Loading…
Reference in New Issue