Publish Articles on Blogger in Just one Second

Swaroop
6 min readDec 28, 2017

--

Two days ago, I have written the article My semi automated workflow for blogging. In that article, one of the steps, I hadn’t yet automated, was publishing on blogger and I said I was going to implement it soon. So, this tutorial is a continuation for that. In this article I’ll show how you can upload files to Blogger automatically and will also show you how I’m planning to make use of this in my own blogging workflow.

Before all of that, let me tell you about a couple of things that happened when I was researching about automating the Blogger interaction. I have started looking into using Google’s Blogger API’s and started trying out some stuff but soon realized that there are a lot of things to manage and take care of, which I certainly won’t be able to finish in time to publish this article. Then I thought somebody would’ve already done it and would’ve provided a uniform way to get this working. So, Instead of trying to figure that out on my own, I decided to look for what others have done for blogger automation. And this is what I found.

I have found a couple of tools for this, but the one I’ve decided to go with is Easy Blogger by Raghu. I’ve taken a liking for it because of its good documentation and clean interface, and this is what I’ll use for publishing articles to blogger from now on.

The instructions in the project’s README are already quite self sufficient but to keep this article comprehensive, I’m going to add some of the setup and usage instructions.

Setting up

You can install Easyblogger with pip by running pip install EasyBlogger, which will install the easyblogger executable and also the relevant dependencies.

A pretty cool thing about this tool is that you can choose to publish a wide range of formats which will be converted to html in the end using pandoc. So, you can write your document in markdown and directly publish it with this tool. I would love to directly use this, but since I already convert my markdown to html as I’ve described here, I’ll just be publishing the html directly.

The README also explains a couple of Vim mappings if you use Vim and like to publish the articles without leaving your editor. Yay for that!

Then you need to setup the authentication by getting your client keys. For that, you run

easyblogger --blogid <yourblogid> get

This will open up a browser window that you use to authenticate with your account and once authenticated, easyblogger stores those credentials in the aptly named file ~/.easyblogger.credentials

Once that is done, you’re all set to use Easyblogger.

Usage

A quick help shows all the commands and options available:

$ easyblogger --help
usage: easyblogger [-h] [-i CLIENTID] [-s SECRET]
[-v {INFO,DEBUG,WARNING,ERROR,CRITICAL}]
[--blogid BLOGID | --url URL]
{get,post,delete,update,file} ...
Easily manage posts on Blogger blogspositional arguments:
{get,post,delete,update,file}
sub-command help
get list posts
post create a new post
delete delete a post
update update a post
file Figure out what to do from the input file
optional arguments:
-h, --help show this help message and exit
-i CLIENTID, --clientid CLIENTID
Your API Client id
-s SECRET, --secret SECRET
Your API Client secret
-v {INFO,DEBUG,WARNING,ERROR,CRITICAL}, --verbose {INFO,DEBUG,WARNING,ERROR,CRITICAL}
verbosity(log level) - default CRITICAL
--blogid BLOGID Your blog id
--url URL Your blog url

Fetch posts

Let’s start by getting files from the blog. You can do that with

easyblogger --blogid <blogid> get

This will print out all the titles of the posts along with their post-id’s. But of course if you’ve hundreds and thousands of posts, you would want to limit the posts by a particular label or even limit it to just a few posts. You can do that by adding options in the following way,

easyblogger --blogid <blogid> get --labels programming --count 5

Which gives the following output for my blog, showing the last 5 programming articles.

437344021642199000,Datasets in Apache Spark | Part 1,http://www.freblogg.com/2017/12/apache-spark-datasets-1.html
226912361219823323,Tweeting with Python and Tweepy,http://www.freblogg.com/2017/12/tweeting-with-python-and-tweepy.html
345235372397413038,How to recover from 'git reset --hard" | Git,http://www.freblogg.com/2017/09/how-to-recover-from-git-reset-hard-git.html
63494528537546270,Functions in C Programming | Part 1,http://www.freblogg.com/2017/08/functions-in-c-programming-part-1.html
304802860468725657,Understanding Git Octopus Merge,http://www.freblogg.com/2016/12/git-octopus-merge.html

And to fetch just one post, grab a postid from above and run,

easyblogger.exe --blogid <blogid> get -p 437344021642199000 -d markdown

This outputs the post on the console.

Note: Although the README said this would print in markdown, I got just html. I haven’t yet figured out what could be causing this. I will probably raise an issue on the projects github. But, this feature is not really important for me anyway. So, I’m good with that.

Publish posts

The usage instructions for the post method are as follows:

usage: easyblogger post [-h] [-t TITLE] [-l LABELS] [--publish]
(-c CONTENT | -f FILE)
[--filters FILTERS [FILTERS ...]]
[--format {commonmark,creole,docbook,docx,epub,gfm,haddock,html,json,latex,markdown,markdown_github,markdown_mmd,markdown_phpextra,markdown_strict,mediawiki,muse,native,odt,opml,org,rst,t2t,textile,tikiwiki,twiki,vimwiki}]
optional arguments:
-h, --help show this help message and exit
-t TITLE, --title TITLE
Post title
-l LABELS, --labels LABELS
comma separated list of labels
--publish Publish to the blog [default: false]
-c CONTENT, --content CONTENT
Post content
-f FILE, --file FILE Post content - input file
--filters FILTERS [FILTERS ...]
pandoc filters

As you can see, you can set the title of the article, set labels, and also pass file in pretty much every text format imaginable. I am going to use it with the -f flag by passing the markdown file and with some labels.

As a test run, I’ve created this post on my experimental blog, with this command:

easyblogger.exe --blogid <blogid> post -t "Posted from CL using EasyBlogger" -l "blogging, easyblogger" --publish -f test.html

If you don’t like to publish the post straightaway and instead would like to just save it to drafts, you can do that by removing the --publish option from the above command. And that will save the post as a draft.

Updating a Post

You can update a previously published post like so:

easyblogger update -t 'A new title' -l "new,labels" 3295765957555899963

That will update the title and labels of the given post.

Deleting a Post

This may be not for everybody as most won’t delete their posts once published. But, of course, you can do that as well, by running delete with the postid.

easyblogger delete 234546720561632959

I think that covers the major chunk of how you can work with EasyBlogger. For more details, do read the README.md in the project which contains thoroughly documented commands.

As I’m going to publish this article in Medium, I won’t be able to use this for this post, but for all of my future blogger posts, I’ll definitely use this.

That is all for this article.

For more programming articles, checkout Freblogg

Some articles on automation:

Web Scraping For Beginners with Python

My semi automated workflow for blogging

This is the sixth article as part of my twitter challenge #30DaysOfBlogging. Twenty-four more articles on various topics including but not limited to Java, Git, Vim, Software Development, Python, to come.

If you are interested in this, make sure to follow me on Twitter @durgaswaroop. While you’re at it, Go ahead and subscribe here on medium and my other blog as well.

If you are interested in contributing to any open source projects and haven’t found the right project or if you were unsure on how to begin, I would like to suggest my own project, Delorean which is a Distributed Version control system, built from scratch in scala. You can contribute not only in the form of code, but also with usage documentation and also by identifying any bugs in the functionality.

Thanks for reading. See you again in the next article.

--

--