irc-rss-listener

IRC bot to post RSS updates for garbash
git clone git://git.alexkarle.com.com/irc-rss-listener
Log | Files | Refs | README

irl.sh (1216B) [raw]


      1 #!/bin/sh
      2 # irl -- irc-rss-listener
      3 set -e
      4 
      5 die() {
      6 	echo "$*" 1>&2
      7 	exit 1
      8 }
      9 
     10 usage() {
     11 	die 'Usage: irl.sh -c CHANNEL [-h HOST] [-p PORT]'
     12 }
     13 
     14 port=6667
     15 host=localhost
     16 
     17 args=$(getopt c:h:p: $*)
     18 if [ $? -ne 0 ]; then
     19 	usage
     20 fi
     21 
     22 set -- $args
     23 while [ $# -ne 0 ]; do
     24 	case "$1"
     25 	in
     26 		-c)
     27 			channel="$2"; shift; shift;;
     28 		-h)
     29 			host="$2"; shift; shift;;
     30 		-p)
     31 			port="$2"; shift; shift;;
     32 		--)
     33 			shift; break;;
     34 	esac
     35 done
     36 
     37 [ -z "$channel" ] && usage
     38 
     39 
     40 notify() {
     41 	nc $host $port <<EOM >/dev/null
     42 NICK rssbot
     43 USER rssbot rssbot $host :rssbot
     44 PRIVMSG #$channel :New post '$1' here: $2
     45 QUIT
     46 EOM
     47 }
     48 
     49 feeds=/etc/irl/$host.$channel
     50 known_ids=/tmp/irl-known.$host.$channel.ids
     51 all_ids=/tmp/irl-all.$host.$channel.ids
     52 new_ids=/tmp/irl-new.$host.$channel.ids
     53 
     54 [ ! -e $feeds ] && die "Create $feeds to begin!"
     55 command -v sfeed >/dev/null || die "sfeed not installed"
     56 
     57 # Truncate last pull
     58 >"$all_ids"
     59 
     60 for feed in $(cat "$feeds"); do
     61 	curl -sS "$feed" | sfeed | \
     62 		awk -F'	' "{ print \$3, \$2 }" >>"$all_ids"
     63 done
     64 
     65 if [ -e "$known_ids" ]; then
     66 	diff "$known_ids" "$all_ids" | grep '^>' | sed 's/^..//' > "$new_ids"
     67 	while read url subj; do
     68 		notify "$subj" "$url"
     69 	done < "$new_ids"
     70 fi
     71 
     72 # Update
     73 cp -f "$all_ids" "$known_ids"