Saturday 14 November 2009

Twitpic from the Command Line in Linux

I've just put together a short script for automatically taking a webcam pic then uploading it to Twitter.

Yes, I know what you're thinking, no I don't know why either. I had help from other places that I found through googling. Here it is in case you want to try it out:

#!/bin/bash

# Script to automate posting of webcam images to twitpic

IMGDIR="/location_to_save_webcam_pics"
STAMP=`date +%m%d%Y_%s`
IMG="$IMGDIR/"webcam_""$STAMP".jpeg"
USERNAME="twitter_username"
PASSWORD="twitter_password" # Don't forget to escape special chars with "\"
MESSAGE="Webcam snapshot, `date`"

# Take picture from webcam
TAKE=`streamer -o $IMG`
echo "$TAKE"

# Upload to twitpic using curl
curl -F "username=$USERNAME" -F "password=$PASSWORD" -F "message=$MESSAGE" -F media=@"$IMG" http://twitpic.com/api/uploadAndPost

I really need to find a way to post code on blogger. The next step is that this script can be added to a cron job and made to feed random pics at intervals.

I'm now trying to think what other interesting things I can send to twitter from Ubuntu?

No comments:

Post a Comment

Flame away, but prepare to be burnt!