From c945f05c3d64da19c2494b71d1e694f05bebc794 Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 22 Feb 2017 18:37:28 +0100 Subject: [PATCH] Added '--stats'. --- .../CommandLineController.java | 20 +++++++++++++++++++ .../telegram_backup/CommandLineOptions.java | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java index fbf6bb3..61f101f 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineController.java @@ -29,6 +29,8 @@ import java.io.IOException; import java.util.List; import java.util.Scanner; import java.util.Vector; +import java.util.HashMap; +import java.util.Map; import org.slf4j.LoggerFactory; import org.slf4j.Logger; @@ -92,6 +94,11 @@ public class CommandLineController { } } + if (CommandLineOptions.cmd_stats) { + cmd_stats(); + System.exit(0); + } + if (CommandLineOptions.val_test != null) { if (CommandLineOptions.val_test == 1) { TestFeatures.test1(); @@ -210,6 +217,18 @@ public class CommandLineController { return account; } + private void cmd_stats() { + HashMap map = new HashMap(); + map.put("count.accounts", Utils.getAccounts().size()); + map.put("count.messages", Database.getInstance().getMessageCount()); + map.put("messages.top_id", Database.getInstance().getTopMessageID()); + for(Map.Entry pair : Database.getInstance().getMessageMediaTypesWithCount().entrySet()) { + map.put(pair.getKey(), pair.getValue()); + } + + System.out.println(map.toString()); + } + private void cmd_login(String phone) throws RpcErrorException, IOException { UserManager user = UserManager.getInstance(); if (phone==null) { @@ -267,6 +286,7 @@ public class CommandLineController { System.out.println(" --license Displays the license of this program."); System.out.println(" -d, --daemon Keep running and automatically save new messages."); System.out.println(" --anonymize (Try to) Remove all sensitive information from output. Useful for requesting support."); + System.out.println(" --stats Print some usage statistics."); } private void list_accounts() { diff --git a/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java b/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java index ac653b1..bf217c4 100644 --- a/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java +++ b/src/main/java/de/fabianonline/telegram_backup/CommandLineOptions.java @@ -29,6 +29,7 @@ class CommandLineOptions { public static boolean cmd_daemon = false; public static boolean cmd_no_media = false; public static boolean cmd_anonymize = false; + public static boolean cmd_stats = false; public static String val_account = null; public static Integer val_limit_messages = null; @@ -112,6 +113,9 @@ class CommandLineOptions { case "--anonymize": cmd_anonymize = true; break; + + case "--stats": + cmd_stats = true; break; default: throw new RuntimeException("Unknown command " + arg);