View Single Post
  #3   Report Post  
Posted to rec.crafts.metalworking
DoN. Nichols DoN. Nichols is offline
external usenet poster
 
Posts: 2,600
Default Bash function to post to Twitter via command line

On 2009-03-25, Ignoramus23425 wrote:
################################################## ##### Twitter
# Usage:
#
# Twitter I am eating sushi right now
#
Twitter() {
local USERNAME=myusername
local PASSWORD=mypassword

# Verify that you have URI::Escape perl module.
if perl -MURI::Escape -e exit; then
true
else
echo "perl Module URI::Escape missing. You need to install it." 1&2
return 1
fi

MESSAGE=$(echo -n "$@" | perl -MURI::Escape -ne 'print uri_escape( $_ )')

COMMAND="curl --basic --user $USERNAME:$PASSWORD --data-ascii status=$MESSAGE http://twitter.com/statuses/update.json"
$COMMAND /dev/null 2&1 && echo Success.
}


Nice and simple -- but I would have added a test to make sure that the
username and password had been set to something other than the defaults
you have in there. Or perhaps able to read them from a file like
~/.twitter/accountname so you could use it for mutiple accounts by
typing "twitter junque I am eating sushi right now" and it would read
the username and password for account "junque" before proceeding.

Now -- all I need to do is to create a twitter account -- and
find people who are interested enough in my day-to-day minutiae to read
it. :-)

Thanks,
DoN.

--
Email: | Voice (all times): (703) 938-4564
(too) near Washington D.C. | http://www.d-and-d.com/dnichols/DoN.html
--- Black Holes are where God is dividing by zero ---