From 59aee5158fca433d073ba908a63e2e89c6ee86ae Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Fri, 6 Apr 2018 22:04:18 +0200 Subject: convert.sh: understand ACTION, too --- convert.sh | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/convert.sh b/convert.sh index 175195a..0663566 100755 --- a/convert.sh +++ b/convert.sh @@ -4,6 +4,26 @@ dir='/srv/arch-mirror/arch/arch/archlinux32/irc-logs/#archlinux-ports/' declare -A colors +create_color() { + if [ -z "${colors["$1"]}" ]; then + colors["$1"]=$( + find "${dir}" -type f -name '*-*-*.html' -exec \ + grep -h "style=\"color:#[0-9a-f]\{6\}\"><$1>" {} \; | \ + sed 's@.* style="color:#\([0-9a-f]\{6\}\)"><.*@\1@' | \ + sort -u + ) + fi + if [ -z "${colors["$1"]}" ]; then + colors["${b}"]=$(hexdump -n 4 -e '4/4 "%08X" 1 "\n"' /dev/urandom | head -c 6) +# >&2 printf 'unkown user "%s"\n' "$1" +# exit 42 + fi + if [ $(echo "${colors["$1"]}" | wc -l) -ne 1 ]; then + >&2 printf 'user "%s" has multiple colors\n' "$1" + exit 42 + fi +} + if [ "$1" = 'html' ]; then shift sed -n ' @@ -31,6 +51,11 @@ if [ "$1" = 'html' ]; then } d } + \@ \*\*\*\S\+ @{ + s@^(\([^)]\+\)) \*\*\*\(\S*\) \(.*\)
$@\1 * | \2 \3@ + p + d + } //{ s@^(\([^)]\+\)) \(\S\+\): @\1 \2 | @ s@
$@@ @@ -82,23 +107,15 @@ while read -r a b dummy c; do "${time}" "${time}" "${time}" "${before}" "${after}" continue fi - if [ -z "${colors["${b}"]}" ]; then - colors["${b}"]=$( - find "${dir}" -type f -name '*-*-*.html' -exec \ - grep -h "style=\"color:#[0-9a-f]\{6\}\"><${b}>" {} \; | \ - sed 's@.* style="color:#\([0-9a-f]\{6\}\)"><.*@\1@' | \ - sort -u - ) - fi - if [ -z "${colors["${b}"]}" ]; then - colors["${b}"]=$(hexdump -n 4 -e '4/4 "%08X" 1 "\n"' /dev/urandom | head -c 6) -# >&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 + if [ "${b}" = '*' ]; then + nick="${c%% *}" + action="${c#* }" + create_color "${nick}" + printf '[%s] * %s %s\n
\n' \ + "${time}" "${time}" "${time}" "${colors["${nick}"]}" "${nick}" "${action}" + continue fi + create_color "${b}" printf '[%s] <%s> %s\n
\n' \ "${time}" "${time}" "${time}" "${colors["${b}"]}" "${b}" "${c}" done -- cgit v1.2.3