#!/bin/sh base="https://twitter.com" tweeircdir="/tmp/tweeirc" irc_channel="#twitter" irc_server="localhost" irc_port="6666" refresh_time="3600" # # Given a username print to standard output all tweets newer than the id stored # in fileid. # tweets() { username=$1 curl -gs "${base}/${username}" | tscrape | sort -n | awk -F '\t' \ -v fileid="${tweeircdir}/${username}" ' BEGIN { getline min_id < fileid min_id = int(min_id) max_id = 0 } { timestamp = $1 username = $2 text = $4 item_id = $5 item_username = $6 item_retweetid = $8 item_pinned = $9 id = item_retweetid ? item_retweetid : item_id id = int(id) max_id = id > max_id ? id : max_id } (id > min_id) { if (username != item_username) printf("RT @%s ", item_username) printf("%s\n", text) } END { if (max_id > min_id) print max_id > fileid } ' } # # Given a username, pipe to the IRC channel # irc() { username=$1 awk -v nc="nc ${irc_server} ${irc_port} > /dev/null" \ -v channel="${irc_channel}" \ -v username="${username}" ' BEGIN { print "NICK " username | nc print "USER " username " * * *" | nc fflush(nc) } { print "PRIVMSG " channel " :" $0 | nc fflush(nc) } END { print "QUIT" | nc close(nc) } ' } # # Given an IRC server, port and channel fetch all Twitter user timelines, # parse them via tscrape and share each tweet on the IRC channel with the # proper nick. # mkdir -p "${tweeircdir}" while :; do for u in "$@"; do tweets "$u" | irc "$u" done sleep "${refresh_time}" done