#!/bin/bash # a twitter client (uses .netrc for auth) confdir=~/.bt seenfile=$confdir/seen feedstyle=$confdir/btfeed.xsl if [ "$1" == "-h" ]; then echo " use: $(basename $0) -h | [ tweet ]" echo " -h help" echo " -i install" echo " no arguments gets latest updates" exit fi function binstall { local sheet=' : <> \n ' if [ ! -d $confdir ]; then mkdir -p $confdir; fi if [ ! -e $seenfile ]; then touch $seenfile; fi if [ ! -e $feedstyle ]; then echo -e $sheet > $feedstyle fi } function friends { local tnow=$( date --utc +%s ) local tthen=$( date --utc --reference=$seenfile +%s ) if [ $(( tnow - tthen < 60 )) = 1 ]; then return fi local tmpfile=$( mktemp $confdir/result.XXXXXXXX ) curl --connect-timeout 5 -s -n $1 | xsltproc --novalid $feedstyle - > $tmpfile local tmpu=$( mktemp ~/.bt/uniques.XXXXXXXX ) cat $seenfile $tmpfile | sort -n | uniq -u > $tmpu cat $seenfile $tmpfile | sort -n | uniq > $seenfile cat $tmpu $tmpfile | sort -n | uniq -d | cut -d':' -f2- echo rm $tmpfile $tmpu touch $seenfile } function update { curl -s -n -d "status=$msg" $1 &>/dev/null || echo "tweet broke" } if [ "$1" == "-i" ]; then binstall exit fi if [ -t 0 ]; then msg="$*"; else msg="$(cat -)"; fi if [ "$msg" ];then update http://twitter.com/statuses/update.xml else friends http://twitter.com/statuses/friends_timeline.xml fi