#!/bin/rc # pim/who -- who you met with, over a range of days. # # pim/who the last seven days # pim/who -n 30 the last thirty # pim/who -a only those who accepted # pim/who -x calvinm leave yourself out rfork e mtpt=/mnt/pim days=7 only=() me=() acc=() while(~ $1 -*){ switch($1){ case -m mtpt=$2; shift case -n days=$2; shift case -x me=$2; shift case -a acc=1 case -c only=($only $2); shift case * echo 'usage: who [-m mtpt] [-n days] [-x me] [-a]' >[1=2] exit usage } shift } now=`{date -n} from=`{date -i `{echo $now - $days '*' 86400 | bc}} to=`{date -i `{echo $now + 86400 | bc}} cals=$only if(~ $#cals 0) cals=`{pim/calendars -m $mtpt} # Who counts as you comes from the calendar's me= in the config, which # the server reports in ctl. -x adds to it. ex=/tmp/who.ex.$pid fn sigexit { rm -f $ex $tmp } >$ex if(! ~ $#me 0) echo $me >>$ex for(c in $cals) sed -n 's/^cal .* me //p' $mtpt/calendars/$c/ctl >[2]/dev/null | tr , ' ' | tr ' ' ' ' >>$ex grep -v '^$' $ex >$ex^.t; mv $ex^.t $ex hits=() for(c in $cals){ echo 'from='^$"from^' to='^$"to >$mtpt/calendars/$c/query for(r in `{cat $mtpt/calendars/$c/query}) hits=($hits $mtpt/calendars/$c/$r) } if(~ $#hits 0){ echo 'nobody, in the last '^$"days^' days' exit 0 } fn people { for(h in $hits){ d=`{basename -d $h} ev=`{sed -n 's/^event: //p' $h} if(! ~ $#ev 0){ f=$d/$"ev/attendees if(test -f $f){ if(~ $#acc 0) awk -F'\t' 'NF>2{print $3}' $f if(! ~ $#acc 0) awk -F'\t' 'NF>2 && $1 ~ /ACCEPTED/{print $3}' $f } } } } if(test -s $ex) people | grep -v -f $ex | sort | uniq -c | sort -nr if(! test -s $ex) people | sort | uniq -c | sort -nr exit 0