#!/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 your status in twitter
# AUTHOR: Hemanth H.M, hemanth.hm@gmail.com
# VERSION: 1.0
# CREATED: 03/06/2010 01:45:02 AM IST
#==================================================================
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.
# Declares an associative array called data (Bash v4+)
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 media=@"$PHOTO" \
--form message="$TWEET_MSG" $UPLOAD_URL
# Check if all went fine
[[ $? = 6 ]] && echo "Error while uploading! Check credentials" && exit 1
echo "Pic uploaded!"
#bash#linux#cli
About Hemanth HM
Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.