Table of Contents

5. Tangled Web, Not At All!

Downloading from a web page

Downloading a web page as plain text

A primer on cURL

Accessing Gmail e-mails from the command line

Parsing data from a website

Image crawler and downloader

Web photo album generator

Twitter command-line client

  1. We need to download the bash-oauth library from https://github.com/livibetter/bash-oauth/archive/master.zip
  2. Then install from the sub dir bash-oauth-master with:
    # make install-all
  3. Go to https://dev.twitter.com/apps/new and register a new app.
  4. Provide read/write access to the new app.
  5. Retrieve the consumer key and the consumer secret
  6. Then use the following script:
    #!/bin/bash
    #Filename: twitter.sh
    #Description: Basic twitter client
    oauth_consumer_key=YOUR_CONSUMER_KEY
    oauth_consumer_secret=YOUR_CONSUMER_SECRET
    config_file=~/.$oauth_consumer_key-$oauth_consumer_secret-rc 
    if [[ "$1" != "read" ]] && [[ "$1" != "tweet" ]];
    then 
      echo -e "Usage: $0 tweet status_message\n   OR\n      $0 read\n"
      exit -1;
    fi
    source TwitterOAuth.sh
    TO_init
    if [ ! -e $config_file ]; then
     TO_access_token_helper
     if (( $? == 0 )); then
       echo oauth_token=${TO_ret[0]} > $config_file
       echo oauth_token_secret=${TO_ret[1]} >> $config_file
     fi
    fi
    source $config_file
    if [[ "$1" = "read" ]];
    then
      TO_statuses_home_timeline '' 'shantanutushar' '10'
      echo $TO_ret | sed 's/<\([a-z]\)/\n<\1/g' | \
    grep -e '^<text>' -e '^<name>' | sed 's/<name>/\ - by /g' | \
    sed 's$</*[a-z]*>$$g'
    elif [[ "$1" = "tweet" ]];
    then 
      shift
      TO_statuses_update '' "$@"
      echo 'Tweeted :)'
    fi

Creating a "define" utility by using the Web backend

Tracking changes to a website

Posting to a web page and reading the response