#!/bin/sh # # reportfollowers.sh # # Send a diff of the follower dumps stored under ./followers per mail, # designed to be run daily from cron. # # The optional argument overrides the timestamp to compare against, which # defaults to "yesterday" # # Copyright © 2017–2019 by martin f. krafft # Released under the Artistic Licence 2.0 # set -eu MYDIR="${0%/*}" cd "$MYDIR"/followers export LC_ALL=$(locale -a | grep utf8 | head -1) REVSPEC="${1:-master@{yesterday\}}" DATESTAMP="$(git show --pretty=format:'%ai (%ar)' --no-patch $REVSPEC)" COUNT=$(wc -l dump | cut -d' ' -f1) STATS="$(git diff --numstat $REVSPEC | \ sed -re 's,([[:digit:]]+)[[:space:]]+([[:digit:]]+).*,+\1/-\2,')" SENDMAIL="/usr/sbin/sendmail madduck@madduck.net" [ ! -t 0 ] || SENDMAIL=cat $SENDMAIL <<_eof From: Twitter follower report Subject: $(wc -l dump | cut -d' ' -f1) followers ($STATS) Changes since $DATESTAMP: $(git diff $REVSPEC | grep '^[-+][^-+]' | sort -k1.1,1.1) =Total followers: $COUNT _eof