It's the little things that help make things better

Just cleaned up some of the code that generates this blog. I'm using Pelican so one of the pain-points is creating a template for each new post. I have a script called "" that does this. I also post a monthly check-in for my "Designing a Well Lived Life" challenge, which required me to import a new template each time.

One of my maxims is if I have to remember to do things more than once then it needs to be automated.

So I set about replacing the old crufty code (using argparse) with something that better suited my needs.

First off, I needed to have some way of passing the month / year for the title. I also needed a way to pass the location of the template and the title itself (which is true of all posts).

It's not pretty and will likely change in the future, but here's my first-pass at this:

TEMPLATE="/home/craig/Documents/zen_habits/designing_a_well_lived_life/" --titlemonth $1 --titleyear $2 --templatefile $TEMPLATE "Designing a Well Lived Life: Checking In ($1 $2)"

#!/usr/bin/env python3
import sys
import click
from datetime import datetime
from subprocess import call
from string import punctuation
from slugify import slugify

# apt install python3-slugify

Title: {title}
Date: {year}-{month}-{day} {hour}:{minute:02d}
Author: craig
Tags: A day in the life
Slug: {slug}
Status: published


@click.option('--titlemonth', default=None, help="Title month")
@click.option('--titleyear', default=None, help="Title year")
@click.option('--templatefile', default=None, type=click.File('r'), help="Template file to use")
def make_entry(title, titlemonth, titleyear, templatefile):
    title = title.strip().format(
    today =
    slug = slugify(title)
    f_create = "/home/craig/projects/pelican/decafbad/content/{}_{:0>2}_{:0>2}_{}.md".format(
        today.year, today.month,, slug)
    template = TEMPLATE
    if templatefile is not None:
        template =

    t = template.strip().format(
    with open(f_create, 'w') as w:
    print("File created -> " + f_create)
    call(['vim', f_create])

if __name__ == '__main__':

With the new code I could make parameters for the items that I needed. The TEMPLATE="/home/craig/Documents/zen_habits/designing_a_well_lived_life/" file has the TEMPLATE part in the header so I don't have to repeat that with my normal TEMPLATE block.

This saves me a few keystrokes and makes the process easier for me to remember all of the items that normally would be in my mental checklist. And really, isn't that what computers are better at handling than humans?