19 Juli 2010

Updating Twitter Status via Shell Scripts

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.

And here's step by step instructions to do that. :) please read it below carefully. Enjoyed. :)


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 yeehhaaw!! your twitter status has been updated :)












Download the Code
twitter.sh via mekz.googlecode.com
Size: 1.1kb
SHA1 Checksum: 20af0da7cf93a3c7f252fa13b7c326b92e42158b





sumber: less-talk-more-example.info

1 comments:

hwalah. Gak ngerti bhsa inggris. Keep share

→ Komentar yang menyertakan link aktif, iklan atau titip link akan dimasukan ke folder SPAM
→ Gunakan kode ini utk Emoticon (tanpa ♦)
:) ♦ :( ♦ ;) ♦ :p ♦ =( ♦ ^_^ ♦ :D ♦ =D ♦ |o| ♦ @@ ♦ :-bd ♦ :-d ♦ :ngakak: ♦ :lol: ♦ :love: