Guest

Dwight Spencer

By: a guest on May 7th, 2009  |  syntax: Bash  |  size: 1.12 KB  |  hits: 72  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. #!/bin/sh
  2. # tweet.sh version 1.9
  3. # a twitter client in cli
  4. # (C)2008 Dwight Spencer (Den Zuko) <dspencer@computekindustries.co.cc>
  5. # All Rights Reserved.
  6. ######################################################################################
  7. # TODO:
  8. #  * add in checking for wget vs curl and gracefully drop to lwp-get
  9. #  * add in getopt support for username and password, also for https or http
  10. # Chage Log:
  11. #  * added pwsafe support
  12.  
  13. usage() {
  14.   echo "Usage: `basename $0` <status>" && exit 0
  15. }
  16.  
  17. die() {
  18.   echo "Opps something went wrong" && exit 1
  19. }
  20.  
  21. [ [ $# -lt 1 ] && usage
  22. MSG=$1
  23.  
  24. AGENT=$(which curl)
  25. PWSAFE=$(which pwsafe)
  26. [ $? == 1 && die
  27. if [ -f $HOME/.tweetrc ]; then
  28.   auth=`cat $HOME/.tweetrc`
  29. else
  30.   echo -n "Twitter Username: " && read -p "Twitter Username: " user
  31.  
  32.   if [ =f $HOME/.pwsafe.dat ]; then
  33.     pass=$(${PWSAFE} -quE twitter.$user)
  34.   else
  35.     echo -n "Twitter Password: "
  36.     stty -echo && read pass && stty echo
  37.   fi
  38.   auth=${user}:${pass}"
  39.  echo $auth > $HOME/.tweetrc
  40. fi
  41.  
  42. xmlrpc="https://$auth@twitter.com/statuses/update.xml"
  43. $AGENT -d status="${MSG}" $xmlrpc 2>&1 1>/dev/null