Python Generated Post

less than 1 minute read

This is a post generated by a python script. I just made this script to see if I can automate the process of generating a formatted post. Currently it’s just putting in the time format and title and stuffs. In the future I might add some Tag and Category automation to it.

Here’s the script

import sys
import os
import datetime

def NewPost(title = "New Title", tags = []):
    currDate = datetime.datetime.now()
    DateStr = currDate.strftime("%Y-%m-%d")
    TimeStr = currDate.strftime("%H:%M:%S %z")

    path = "./_posts/"
    filename = path + DateStr + "-" + title + ".md"

    file = open(filename, "x")
    file.write("---\n")
    file.write("title: " + title + "\n")
    file.write("date: " + DateStr + " " + TimeStr + "\n")
    file.write("tags: [")
    for tag in tags:
        file.write(tag + ",")
    file.write("]\n")
    file.write("---\n")

    file.close()

if __name__ == "__main__":
    NewPost(sys.argv[1])