CLI twitpic

!/bin/bash

==================================================================

#

FILE: cli-twitpic.bash

USAGE: ./cli-twitpic.bash

DESCRIPTION: Allows you to upload pic from cli to twitpic and # also update the same as you status in twitter

OPTIONS: ---

REQUIREMENTS: ---

BUGS: ---

NOTES: ---

AUTHOR: Hemanth H.M (), [email protected]

VERSION: 1.0

CREATED: 03/06/2010 01:45:02 AM IST

REVISION: ---

=================================================================

URL=http://twitpic.com/api/uploadAndPost

Fields to post in (post data should be formatted as multipart/form-data):

- media (required) - Binary image data

- username (required) - Twitter username

- password (required) - Twitter password

- message (optional) - Message to post to twitter. The URL of the #image is automatically added.

Sample response:

4567

4567

hmh123

http://twitpic.com/hmh123

Read input to an array BASHv4 only, other version tweak to code # to read -a to read it to normal array or use individual variables

Declares an associative array called data

declare -A data

data[USER]=$1 data[PASS]=$2 data[PIC]="$3" data[TWIT]=$4

Validate inputs

for key in USER PASS PIC TWIT; do [[ data[$key]="" ]] && echo "Enter $key:" && read data[$key] done

Check if the pic file exists

[[ -f ${data[PIC]} ]] || echo Error: FileNotFound ${data[PIC]} && exit 1

echo Uploading... $CURL \ --form username=$TWITTER_USER \ --form password=$TWITTER_PW \ --form [email protected]"$PHOTO" \ --form message="$TWEET_MSG" $UPLOAD_URL

Check if all went fine

[[ $? = 6 ]] && echo "Error will uploading! Check credentials" && exit 1 echo "Pic uploaded!"

Share this