rioastamal.net

Just things inside my head…

Tutorial: Updating Twitter Status via Shell Script

Posted by rio On February - 9 - 2010

The Goal

Updating twitter status via shell script. The command used to send the HTTP request is POST a.k.a lwp-request (a perl script) that included in most linux distribution.

Twitter Status Update

The Process

  1. Open your text editor i.e. gedit/geany/etc or even vi you are die hard fans of this editor.
  2. Copy and paste code below.

    #!/bin/bash
    #
    TUNAME="lesstalkme"
    TUPASS=""
    TSTATUS=""
    TURL="http://twitter.com/statuses/update.xml"
    TDATA="source=LTME&status="
     
    # print some fancy header :)
    echo "-----------------------------------------"
    echo "         Twitter Status Updater"
    echo " http://www.less-talk-more-example.info/"
    echo "------------------------------------------"
     
    echo -n "Twitter Password: "
    read -ers TUPASS
    echo -e "\nEnter Twitter Status:"
    read TSTATUS
     
    # replace some characters ( I'm too lazy to replace all the characters :))
    TSTATUS=`echo $TSTATUS | sed 's/ /%20/g'` # space => %20
    TSTATUS=`echo $TSTATUS | sed 's/@/%40/g'` # @ => %40
    TSTATUS=`echo $TSTATUS | sed 's/\//%2F/g'` # / => %2F
    TSTATUS=`echo $TSTATUS | sed 's/:/%3A/g'` # : => %3B
    TSTATUS=`echo $TSTATUS | sed 's/#/%23/g'` # # => %23
     
    # now POST the data
    echo ""
    echo -n "Updating status..."
    echo "${TDATA}${TSTATUS}" | POST -C $TUNAME:$TUPASS $TURL | grep $TUNAME > /dev/null
    # check status
    # ------------
    # successfull request always return XML format that containts our username
    # so we grep that to check the status
    if [ $? -eq 0 ]; then
      echo "DONE."
    else
      echo "ERROR."
    fi
  3. Replace TUNAME value with your own username.
  4. Save to somewhere i.e. /tmp directory just for testing.
  5. Name it twitter.sh
  6. Open the shell terminal in GNOME System » Application » Terminal
  7. Go to /tmp directory and give execute permission to the file.
    $ cd /tmp
    $ chmod +x twitter.sh
  8. Execute the file, you’ll be promted to enter twitter password and status.
    $ ./twitter.sh
  9. Fill it and voila!! your twitter status has been updated :).
    Twitter Status

Screencast



Download the Code

twitter.sh.zip via ziddu.com.
Size: 0.69kb
MD5 Checksum: f9d38c632430a617331cc4f8d298fcf1

Source:
http://www.less-talk-more-example.info/2010/02/update-twitter-status-via-shell-script.html

bookmark bookmark bookmark bookmark bookmark bookmark

Add A Comment