tonybaldwin | blog

non compos mentis

Post to Posterous with bash, curl and vim

leave a comment »

Here we have a nifty little script to post to posterous.com from the bash terminal with vim and curl.

#!/bin/bash
# post to posterous from bash cli with curl
# I could do this with read -p "Enter ur username d0od: " username
# kind of thing, but I just hardwired my info in.
# edit accordingly for your info.
username=YOUR_USERNAME
password=YOUR_PASSWORD
apitok=YOUR_API_TOKEN

# creates a date stamp for naming the post file
filedate=$(date %m%d%y%H%M%S)

# set post title
read -p "Enter a post title: " ptitle

# write post in vim
vim $filedate.ppost pbody="$(cat $filedate.ppost)"

# send post to posterous with curl
if [[ $(curl -X POST -u $username:$password -d "api_token=$apitok" -d "post[title]=$ptitle" -d "post[body]=$pbody" http://posterous.com/api/2/sites/1814977/posts | grep error) ]]; then
echo "Too bad, do0d...FAIL!"
else
echo "Success! Posted to Posterous!"
fi

# moved post to dir for safekeeping.
# you can use different dir, d00d
mv $(pwd)/$filedate.ppost ~/Documents/fposts/

# open a browser for a look-see?
read -p "Shall we have a look in your browser now? (y/n): " browse

if [ $browse = "y" ]; then
	xdg-open http://$username.posterous.com/
fi

exit

Here is first post made with this script to my posterious. In truth, however, I do not use posterous, really. I will be using this information to add posterous support to Xpostulate before the week is out, however, per a user request. The experimentation with curl was to get my head around their API and posting procedure.

Here is the relevant wiki page for this script.

enjoy…

./tony


posted with Xpostulate.

Advertisements

Written by tonybaldwin

September 19, 2011 at 9:46 pm

Posted in baldwinsoftware

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: