twitterscan.sh

#!/bin/sh
# Copyright (c) 2009 Rory Arms - http://www.TrueStep.com/
# Name:		twitterscan.sh 
# Cdate:	2008-06-01
# Description:	Based on the basic "twitracker.sh" script by "ksaver"
#		Scan the twitter public timeline for messages matching any of the keywords.
# Dependencies:	sh(1), date(1), cut(1), grep(1), curl(1),
# Tested on:	OSX/powerpc 10.5, FreeBSD/i386 7.1
# $Id: twitterscan.sh,v 1.1.1.1 2009/04/08 06:13:15 rorya Exp $
#
# ChangeLog:
# 2009-04-06:
# 1. Changed to use bourne shell instead (not all unix-like systems have bash)
# 2. Changed search patters to use the $@ var, so it searches for all terms in list.
# 3. Changed date/time to the more acceptable international ISO-8601 standard
# 4. Reorganized, cleaned up
#
# TODO:
# 1. Implenent getopt(1) to add various options, logging, date formats, refresh period, time zone, etc.

# user knobs
NAME=$(basename $0)
POLLT=60		# how often to poll the public timeline, in seconds
TMPFILE=/tmp/${NAME}.tmp
LOGFILE=/tmp/${NAME}-search.log

# main
AUTHOR="Rory Arms"
VERSION=1
URL="http://twitter.com/statuses/public_timeline.rss"

usage()
{
	echo "Usage: $NAME keyword1 [keyword2 ...]"
	exit 1
}

banner()
{
	echo "$NAME v$VERSION by $AUTHOR starting.. "
	echo
}

# print the keywords we've been told to search for
print_keywords()
{
	for term in "$@"; do
		echo -n "\""$term"\" "
	done
	return
}

# main

if [ -z "$*" ]; then
	usage
fi

banner
echo -n "$(date +%Y-%m-%dT%H:%M%Z): Scanning for: "; print_keywords "$@";
echo

# fetch public timeline and find keyword matches
while true; do
	curl -s $URL |grep '<description>' |cut -d '>' -f 2 |cut -d '<' -f 1 > $TMPFILE
	# loop through all keywords and find matches
	for term in "$@"; do
		# show matching terms from cooked feed file
		grep --color=auto -i "$term" $TMPFILE
		# log matches to logfile
		# grep -i "$term" $TMPFILE >> $LOGF
	done
	sleep $POLLT
done

Generated by GNU enscript 1.6.4.