summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-10-09 13:49:32 +0200
committerErich Eckner <git@eckner.net>2017-10-09 13:49:32 +0200
commit383e61763387cb09280e525b865aa2c62f4d8642 (patch)
tree962b2da635426c3b58a46cd07997c5c71a0cff37
parent4dcaaa55424b38dfd0d2164c6bad6e3a52911c97 (diff)
downloadlogbot-383e61763387cb09280e525b865aa2c62f4d8642.tar.xz
convert.sh new for converting wee chat logs to irc-logbot logs
-rwxr-xr-xconvert.sh59
1 files changed, 59 insertions, 0 deletions
diff --git a/convert.sh b/convert.sh
new file mode 100755
index 0000000..6c54371
--- /dev/null
+++ b/convert.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+dir='/srv/arch-mirror/arch/arch/archlinux32/irc-logs/#archlinux-ports/'
+
+declare -A colors
+
+sed '
+ s/([^()]*@[^()]*) //
+' | \
+sed '
+ :a
+ $!N
+ s/\n\s\+ | / /
+ ta
+ P
+ D
+' | \
+while read -r a b dummy c; do
+ if [ "${dummy}" != '|' ]; then
+ >&2 printf 'wrong dummy "%s"\n' "${dummy}"
+ exit 42
+ fi
+ time=$(
+ date -d@$(($(date -d"${a}" +%s)+3600*6)) +%T
+ )
+ if [ "${b}" = '-->' ]; then
+ name="${c%% *}"
+ channel="${c##* }"
+ printf '<a href="#%s" name="%s" class="time">[%s]</a> -!- <span class="join">%s</span> has joined %s\n<br />\n' \
+ "${time}" "${time}" "${time}" "${name}" "${channel}"
+ continue
+ fi
+ if [ "${b}" = '<--' ]; then
+ name="${c%% *}"
+ reason="${c##* (}"
+ reason="${reason%)*}"
+ printf '<a href="#%s" name="%s" class="time">[%s]</a> -!- <span class="quit">%s</span> has quit [%s]\n<br />\n' \
+ "${time}" "${time}" "${time}" "${name}" "${reason}"
+ continue
+ fi
+ if [ -z "${colors["${b}"]}" ]; then
+ colors["${b}"]=$(
+ find "${dir}" -type f -name '*-*-*.html' -exec \
+ grep -h "style=\"color:#[0-9a-f]\{6\}\">&lt;${b}&gt;" {} \; | \
+ sed 's@.* style="color:#\([0-9a-f]\{6\}\)">&lt;.*@\1@' | \
+ sort -u
+ )
+ fi
+ if [ -z "${colors["${b}"]}" ]; then
+ >&2 printf 'unkown user "%s"\n' "${b}"
+ exit 42
+ fi
+ if [ $(echo "${colors["${b}"]}" | wc -l) -ne 1 ]; then
+ >&2 printf 'user "%s" has multiple colors\n' "${b}"
+ exit 42
+ fi
+ printf '<a href="#%s" name="%s" class="time">[%s]</a> <span class="person" style="color:#%s">&lt;%s&gt;</span> %s\n<br />\n' \
+ "${time}" "${time}" "${time}" "${colors["${b}"]}" "${b}" "${c}"
+done