Friday, June 09, 2017

A Better Blurl: list posts by label, patch posts and other command line blogging goodness

I'm trying to avoid shaving the yak here, but having limited success.

The labels (or tags, as every other blogging platform calls them) on my blog are a mess and I'd like to clean this up. I can do this by hand, but the Blogger procedure for doing this is painfully clumsy to use. What I really want is a command line utility that lets me update labels in bulk. I can't seem to find such a utility, so I'll have to build my own. This isn't as hard as it sounds, as I've previously develoiped blurl, a lightweight Blogger command line tool.

blurl, however, lacked some key features to allow me to develop my label fixing utility. I've now addressed those shortcomings. The latest version of blur, which you can grab here has the following features added to it:

  • The tool now returns all results, not just the first page's worth. In the past, if you asked for a listing of posts, you got the last 30. Now, you'll get every single post on your blog.
  • The list function can optionally accept a label, which will narrow the results to just that label.
  • The tool can now run a search and return back all matching posts.
  • The tool now supports PATCH'ing, which allows you to update a post without having to re-specify every aspect of the post. For example, you can just change the title of a post and leave the content and labels unspecified and unmodified.

With these new changes in place, I should have no problem building my mass-label-changing utility. Stay tuned.

Here's a few examples of the new blurl functionality at work:

# Grant blurl access to my blog
$ blogger_auth -c blogbyben init
https://accounts.google.com/ServiceLogin?XXXXXXXXXXXXXXXXXXXXXXX
Code? XXX
Done

$ export BLURL_AUTH_CTX=blogbyben

# Find out the unique ID of my blog and store it
# in the environment for later commands to use.
$ blurl -a info  -u https://www.blogbyben.com/
12753102:Ben's Journal
$ export BLURL_BLOG_ID=12753102 

# Last 3 posts in 'reviews' (that's plural)
$ blurl -a list -l reviews | head -3 
2534412822419131921:Review: ASUS ZenWatch 3 - Top quality reviews, but a wait-and-see experience
8359106005748061573:Review: Personal: A Jack Reacher Novel
7209997068661197075:Review: The Boys in the Boat: Nine Americans and Their Epic Quest for Gold at the 1936 Berlin Olympics

# Last 3 posts in 'review' (that's singular)
$ blurl -a list -l review | head -3
5631052962590454401:Review: The Time Traveler's Wife
6292599222302015512:Review: A Partial History of Lost Causes
5153762744021255090:Review: Containment

# Move one post from 'review' to 'reviews'
$ blurl -a patch -i 5631052962590454401 -l 'reviews, recommendations'
http://www.blogbyben.com/2017/01/review-time-travelers-wife.html

# Confirm it worked
$ blurl -a list -l reviews | grep -i time
5631052962590454401:Review: The Time Traveler's Wife

$ blurl -a list -l review | grep -i Time
1390162071521669374:Review:  A Tale for the Time Being: A Novel
7280970208702975504:It's Summer Shoe Time -- Giving A New Minimalist Shoe A Chance
1389130645758623727:Review: Longitude: The True Story of a Lone Genius Who Solved the Greatest Scientific Problem of His Time
3086195861781100501:Review: 30 Things Every Woman Should Have and Should Know By The Time She's 30
7655086660726473861:Review: The Life and Times of the Thunderbolt Kid: A Memoir
1579868997134332395:Killing Time In Recovery

No comments:

Post a Comment