Posts Tagged ‘cygwin’

TwitPic upload hack

Tuesday, January 13th, 2009

Some Twitter users have been using TwitPic to link photos to tweets. I, on the other hand, have been using Flickr and Snipr. It’s a PITA, so I’m giving TwitPic a whirl. Sadly, Digsby, does not support TwitPic, and I’m not installing yet another app.

TwitPic has an API, so I rolled my own simple uploader with cygwin and curl. There’s no doubt in my mind that I’ve reinvented the wheel here…

Standard disclaimer applies: this is quick n’ dirty(tm):

#!/bin/bash

# curl executable.  I'm a PC.
CURL=C:/cygwin/bin/curl

# The upload script that will accept the data
UPLOAD_URL=http://twitpic.com/api/uploadAndPost

# Snag stuff off the command line
TWITTER_USER=$1
TWITTER_PW=$2
PHOTO=`cygpath -m "$3"`
TWEET_MSG=$4

# Prompt for message if it's not given
if [ "$TWEET_MSG" = "" ]; then
   read -p "Tweet msg: " TWEET_MSG
fi

# Go
echo Uploading...
$CURL \
  --form username=$TWITTER_USER \
  --form password=$TWITTER_PW \
  --form media=@"$PHOTO" \
  --form message="$TWEET_MSG" $UPLOAD_URL

# Wait for user to read result message
echo
read -p "Press <enter> to continue" bogus

Create a desktop shortcut with uid and password:

C:\cygwin\bin\sh.exe ~/twitpic.sh --userid-- --password--

Now just drag and drop the photo onto the desktop shortcut.