about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--README.org2
-rw-r--r--lib/Taurus/CLI.rakumod29
2 files changed, 30 insertions, 1 deletions
diff --git a/README.org b/README.org
index ed00e54..e867a4d 100644
--- a/README.org
+++ b/README.org
@@ -68,5 +68,5 @@ Exported log file.
 
 Number of significant digits in phone numbers. Default is set to 10. If
 the number of digits is less than significant digits then the number is
-picked, if it's more then the initial extra digits are discarded
+discarded, if it's more then the initial extra digits are discarded
 (Country Code, etc.).
diff --git a/lib/Taurus/CLI.rakumod b/lib/Taurus/CLI.rakumod
new file mode 100644
index 0000000..db6be9e
--- /dev/null
+++ b/lib/Taurus/CLI.rakumod
@@ -0,0 +1,29 @@
+use CSV::Parser;
+use Terminal::UI;
+use Terminal::Spinners;
+use Text::Table::Simple;
+
+#| parses Call Logs
+unit sub MAIN (
+    Str $log where *.IO.f, #= input log file to parse
+    UInt :$digits = 10, #= number of significant digits
+);
+
+my @logs;
+my Str %contacts{Str};
+Spinner.new(:type<bounce2>).await: Promise.start: {
+    my $p = CSV::Parser.new();
+    # 0: Name, 1: Phone number, 2: Call Type, 3: Timestamp,
+    # 4: Duration, 5: Sim used.
+
+    # Turn the Hash to an Array.
+    @logs = @($log.IO.lines.skip.hyper.map({$p.parse($_)})>>.{0..4}
+              # Discard invalid phone numbers.
+              .grep(*.[1].chars >= $digits));
+
+    # Discard non-significant digits from phone numbers.
+    .[1] = .[1].substr(*-10) for @logs;
+
+    # Build contact list.
+    %contacts{.[1]} = .[0] for @logs.grep(*.[0].chars > 0);
+};