#!/usr/bin/env python import datetime import yaml blog_title = input('title for the entry: ') title_date = input('date for the entry (format:yyyy-mm-dd|defaults to today): ') if not title_date: title_date = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d') tags = input('tags (space seperated): ') filename = "{}-{}.markdown".format( title_date, '-'.join(blog_title.lower().split())) ''' layout: post title: "go: `:=` operator causes accidental shadowing" date: 2016-01-14 21:13 comments: true categories: - go ''' metadata_fmt = """--- layout: post title: "{}" date: {} comments: true categories: {} --- """ catblock = " - {}" cats = map(catblock.format, tags.split()) metadata_fmt = metadata_fmt.format( blog_title, title_date, '\n'.join(cats) ) with open('blog/{}'.format(filename), 'w') as f: f.write(metadata_fmt) print("New entry {} is ready at {} for editing".format( blog_title, filename, ))