#!/bin/rc # # NAME # tw 1.5 - Twitter client # # SYNOPSIS # tw [ -d ] [ -r ] [ -u ] [ tweet ... ] # # DESCRIPTION # -d writes most recent home timeline to stdout every $sleep seconds # -r writes retweets of $username's tweets to stdout and exits # -u writes $username's most recent tweets to stdout and exits # no arguments writes most recent home timeline to stdout and exits # # Assign values to $username, $password, $sleep and $wrap below, # or pass the variables to tw with a separate script. # # SOURCE # http://plan9.stanleylieber.com/rc/tw # # SEE ALSO # http://www.supertweet.net/about/api # http://apiwiki.twitter.com # # BUGS # On Plan 9 systems, $username and $password are ignored and factotum(4) # will prompt to save the SuperTweet username and password. # # LICENSE # Public Domain # tweet=$* if(~ $#username 0) username=() if(~ $#password 0) password=() if(~ $#sleep 0) sleep=30 if(~ $#wrap 0) wrap=72 api_post=http://api.supertweet.net/1/statuses/update.xml api_retweets=http://api.supertweet.net/1/statuses/retweets_of_me.xml api_timeline=http://api.supertweet.net/1/statuses/home_timeline.xml api_user_timeline=http://api.supertweet.net/1/statuses/user_timeline.xml if(test -x /boot/factotum) os=plan9 fn tw_daemon{ while(){ tw_read sleep $sleep } } fn tw_post{ switch($os){ case plan9 hget -p status'='$"tweet $"api_post >[2=1] >/dev/null case * curl -s -u $username:$password -d status'='^$"tweet $"api_post >[2=1] >/dev/null } } fn tw_read{ switch($1){ case direct_messages url=$api_direct_messages case retweets url=$api_retweets case timeline url=$api_timeline case user_timeline url=$api_user_timeline case * url=$api_timeline } switch($os){ case plan9 hget $url | awk '/|/{a[i++]=$0;} END{for(j=i-1; j>=0;) print a[j--] "

";}' | sed 's/<\/screen_name>

/<\/screen_name>:/g' | htmlfmt -l $wrap case * curl -s -u $username:$password $url | awk '/|/{a[i++]=$0;} END{for(j=i-1; j>=0;) print a[j--] "

";}' | sed 's/<\/screen_name>

/<\/screen_name>:/g' | htmlfmt -l $wrap } } if(~ $#tweet 0) tw_read timeline if not{ switch($tweet){ case -d tw_daemon case -r tw_read retweets case -u tw_read user_timeline case * tw_post } }