]> git.g-eek.se Git - users/gustav/scripts.git/commitdiff
[event-participant] Inital on Event participation script
authorGustav Eek <gustav.eek@fripost.org>
Sat, 24 Oct 2020 06:55:28 +0000 (08:55 +0200)
committerGustav Eek <gustav.eek@fripost.org>
Sun, 25 Oct 2020 09:56:00 +0000 (10:56 +0100)
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
event-participant [new file with mode: 0755]

index 2950065f0d53363009b3427461ac256417f4b356..74365ebbf2192fb27529d2511f1eda94d424ff60 100644 (file)
--- 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 (executable)
index 0000000..6c7664c
--- /dev/null
@@ -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