Friday, October 16, 2015

blurl: A lightweight command line Blogger client

I've always wanted a Blogger command line client. That way, if I've got ssh (and I've always got ssh), I know that I can publish, and more importantly, fix content anywhere. Also, with a command line tool, automating publishing becomes downright easy. For on the go editing there are Blogger Apps available, but most of them do some sort of mucking with your HTML. My imaginary Blogger command line tool would be pretty strict on this: whatever HTML you fed it, it would use. Nothing more, nothing less.

For a while, there was google-cl which had huge promise. But it's now defunct.

The Blogger API is easy to use, and I've figured out how to do Google authentication with curl, so how hard could putting my own client together be? Well, so far, not hard at all.

I give you blurl (Blogger + Curl). You can grab the latest version here.

Right now, I've done the easy part, which involves all public operations. Here's a sample session:

# Find out the ID associated with my blog
$ ./blurl info http://blogbyben.com
{
 "kind": "blogger#blog",
 "id": "12753102",
 "name": "Ben's Journal",
...

# Get a list of last 30 posts
$ ./blurl posts
546806421583382922:Two Lessons From, And Two Projects For the Lulav and Etrog
8779022495955246592:Smart as a box of hammers: using a physical object to make smart decisions
4337286828478745687:Finally: Hiking Billy Goat A And The $0.38 Game Changing Piece of Gear
4111690764965032609:A Little Arlington Hiking Fun
6695584455756443319:The Power of Trail Tacos
...

# Retrieve all the info about a given post
$ ./blurl lookup 6695584455756443319
{
 "kind": "blogger#post",
 "id": "6695584455756443319",
 "blog": {
  "id": "12753102"
 },
 "published": "2015-10-09T08:20:00-04:00",
...

# Pull back the HTML associated with a given post
$ ./blurl get 6695584455756443319
<p>The ideal backpacking food works like so: you boil water,
pour the boiling water into pouch containing your meal, close up the
...

blurl relies not only curl, but also jq. jq let's you work with JSON on a Unix command line with ease. For example, if I wanted to know the labels used on a given post, I could run:

$ ./blurl lookup 1893920053557993767 | jq .labels
[
  "arlington",
  "photography"
]

Next up, I need to add support for authenticated operations including publishing and updating posts.

Update: Well that didn't take long to invalidate the above transcript. I just checked in a new strategy. All the commands (info/posts/get) now return back JSON which can be further filter with jq. For convenience, I added support for -q which returns a quick response. So blur -q info http://blogbyben.com returns just the ID and Title of the blog. Drop the -q and you get the full JSON response.

No comments:

Post a Comment