My Semi Automated Blogging Workflow | Python
Never have I realized the importance of having an automated workflow, especially for blogging, than in the last couple of days since starting my #30DaysOfBlogging. Before that I use to blog once in a blue moon and giving me plenty of time to do everything starting from research to writing and review. But since as part of this challenge, I am trying to write an article every day and so I don’t have the same amount of time especially with my day-job. So, to keep the flow smooth and uniform, I’ve decided to automate what I was doing and this is the first attempt at it.
As you can probably I guess, I don’t like spending time doing trivial things, especially not when I can automate them. And that’s exactly what I’ve started to do and this article is about what I’ve achieved so far in that process. Do keep in mind that this is still unrefined as I’ve put this together just yesterday. There are still enough things to add to it to make it really automated. I will probably put together another article once that is done.
These are things that I do as part of my blogging workflow once I’ve decided to write about something.
- Open a markdown file in Vim with the title of the article as the name
- Convert markdown to html with pandoc several times during the writing process
- Once the article is done and html is produced, edit the html to make some changes specific based on whether I’m publishing on Medium or if I’m publishing on Blogger
- Open blogger or medium, add a new post and paste in the code and add the title
- Add relevant tags for the article
- Schedule or Publish it
And so far, I’ve only worked on the first three steps and this is what I’ve done for each of the steps.
I have a script
blog.py to create markdown and html files at the beginning.
Script to create md and html files with the given titlegist.github.com
I have an alias setup to run this.
alias blog="python ~\Desktop\30DaysOfBlogging\blog.py"
With that I can do
blog Blogging_workflow & and it will open
gvim with the markdown file
Then I have another script
m2h.py for converting markdown to html. This uses
pandoc and runs a continuous loop to convert the file to html every 10 secs.
I have another alias setup to run this
alias m2h="python ~\Desktop\30DaysOfBlogging\m2h.py"
And with that, I can do
m2h Blogging_workflow.md and it keeps converting md to html every 10 seconds. This step could be made better by making the pandoc conversion happen on file change instead of doing it every 10 secs. But that is not a big concern for me right now. I’ll probably add that once I’m through with the major stuff.
Then for the third step, It gets a bit tricky based on if I’m going to publish that article on Blogger or Medium. In-case of Blogger, most likely I’m done with step 2. I could directly use the generated html code. But, If I’m using Medium, it is still a manual process I’m afraid, as Medium doesn’t have markdown or html support. What I do for that is, I copy the text from the browser and paste it in Medium and then make any necessary changes. [If you have ideas about what can be done here, please do let me know]
For the last three steps I would have to use the blogger API’s or the medium API’s. I need to spend sometime with that to get them working which I’m planning to do soon.
And finally to put everything together, I have one bash script
# To make the aliases available in the script
shopt -s expand_aliases
blog $1 &
chrome $1.html &
And when I run something like
blog-it Automated_Blogging, it opens the markdown file in an editor, opens the html file in chrome and sets up the pandoc conversion as well. And all I’ve to do is keep writing. Pretty sweet!
To see the latest changes in the browser, I’d still have to keep the browser refreshing but that’s something I’m fine with for now, as I don’t do it that often. But, of course for a truly automated process, that needs to setup as well. I’ll probably need to setup a server and keep refreshing the page.
That is all for this article.
This is the fourth article as part of my twitter challenge #30DaysOfBlogging. Twenty-six 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](https://twitter.com/durgaswaroop). While you’re at it, Go ahead and subscribe to this blog and my blogger 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.