summaryrefslogtreecommitdiff
path: root/plugins/zyklonb/seen-import-degesch.pl
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-04-24 21:05:53 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-04-24 21:05:53 +0200
commitd97f28e7f7b76b0e2d458baea5f46bc6cb9be0d5 (patch)
tree848e5d874815372ad2b2f11bb152cacab72b61be /plugins/zyklonb/seen-import-degesch.pl
parentd6a9e1dca19a26e432f404a64e9667faf68c0c95 (diff)
downloadxK-d97f28e7f7b76b0e2d458baea5f46bc6cb9be0d5.tar.gz
xK-d97f28e7f7b76b0e2d458baea5f46bc6cb9be0d5.tar.xz
xK-d97f28e7f7b76b0e2d458baea5f46bc6cb9be0d5.zip
ZyklonB: add a seen plugin
Diffstat (limited to 'plugins/zyklonb/seen-import-degesch.pl')
-rwxr-xr-xplugins/zyklonb/seen-import-degesch.pl39
1 files changed, 39 insertions, 0 deletions
diff --git a/plugins/zyklonb/seen-import-degesch.pl b/plugins/zyklonb/seen-import-degesch.pl
new file mode 100755
index 0000000..ddef6be
--- /dev/null
+++ b/plugins/zyklonb/seen-import-degesch.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+# Creates a database for the "seen" plugin from logs for degesch.
+# The results may not be completely accurate but are good for jumpstarting.
+# Usage: ./seen-import-degesch.pl LOG-FILE... > seen.db
+
+use strict;
+use warnings;
+use File::Basename;
+use Time::Piece;
+
+my $db = {};
+for (@ARGV) {
+ my $where = (basename($_) =~ /\.(.*).log/)[0];
+ unless ($where) {
+ print STDERR "Invalid filename: $_\n";
+ next;
+ }
+
+ open my $fh, '<', $_ or die "Failed to open log file: $!";
+ while (<$fh>) {
+ my ($when, $who, $who_action, $what) =
+ /^(.{19}) (?:<[~&@%+]*(.*?)>| \* (\S+)) (.*)/;
+ next unless $when;
+
+ if ($who_action) {
+ $who = $who_action;
+ $what = "* $what";
+ }
+ $db->{$who}->{$where} =
+ [Time::Piece->strptime($when, "%Y-%m-%d %T")->epoch, $what];
+ }
+}
+
+while (my ($who, $places) = each %$db) {
+ while (my ($where, $data) = each %$places) {
+ my ($when, $what) = @$data;
+ print ":$who PRIVMSG $where $when :$what\n";
+ }
+}