From b2eec10d18996c13982911d21911829741600f18 Mon Sep 17 00:00:00 2001 From: Gustav Eek Date: Sat, 24 Oct 2020 08:55:28 +0200 Subject: [PATCH] [event-participant] Inital on Event participation script Move to this repository from elsewhere. The script reads an email from stdin and adds sender to a list of participants for an event. --- Makefile | 1 + event-participant | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100755 event-participant diff --git a/Makefile b/Makefile index 2950065..74365eb 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ INSTALL = $(HOME)/bin SCRIPTS = \ confluence-tk \ + event-participant \ exiv2-common-edits \ folkets \ ip-check \ diff --git a/event-participant b/event-participant new file mode 100755 index 0000000..6c7664c --- /dev/null +++ b/event-participant @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +EVENT="$1" +CACHE="$HOME/.cache/${0##*/}/events.csv" +HEADER="participant,date_att,date_cancel" +EXPR=" +1,/^$/ { + /^From:\|^Date:/ { + s/^[a-zA-Z]*: *\(.*\)$/\1/ + p + } +} +" + +if [ -f "$CACHE" ]; then + event=$(tail -1 "$CACHE") +else + mkdir -p $(dirname "$CACHE") + echo -n "" > "$CACHE" +fi +if [ -n "$EVENT" -a "$EVENT" != "$event" ]; then + event="$EVENT" + echo "$event" >> "$CACHE" +fi +if [ -z "$event" ]; then + echo "${0##*/}: E: No event file." 1>&2 + exit 1 +fi + +#info=$(cat | sed -n -e "$EXPR" | tr '\n' '|') +info=$(cat | grep '^From:\|^Date:' | tr '\n' ':') + +[[ "$info" =~ (From: )([^:]*) ]] +participant="${BASH_REMATCH[2]}" +[[ "$info" =~ (Date: )([^:]*) ]] +date=$(date -I -d "${BASH_REMATCH[2]}") + +echo "${participant},${date}" | tee -a "$event" +n_t=$(cat "$event" | grep -v "$HEADER"| cut -d, -f2 | grep -v '^$' | wc -l) +n_c=$(cat "$event" | grep -v "$HEADER"| cut -d, -f3 | grep -v '^$' | wc -l) +n_p=$(( $n_t - $n_c )) +echo -ne "At $event:\n part: $n_p\n canc: $n_c\n" 1>&2 -- 2.39.5