24 lines
1.1 KiB
Python
24 lines
1.1 KiB
Python
|
import argparse
|
||
|
from datetime import datetime
|
||
|
|
||
|
# Argument Parser
|
||
|
argparser = argparser = argparse.ArgumentParser(description = "Generate a .md file with a pre-filled title, date, etc.")
|
||
|
argparser.add_argument("output", help = "The location to generate the template to")
|
||
|
argparser.add_argument("--title", help = "The title of the article (default: Blog Post)", default = "Blog Post")
|
||
|
argparser.add_argument("--author", help = "The name of the author (default: Blog Author)", default = "Blog Author")
|
||
|
argparser.add_argument("-v", help = "more output", action = "store_true", dest = "verbose")
|
||
|
args = argparser.parse_args()
|
||
|
|
||
|
date = datetime.now().astimezone().strftime('%Y-%m-%dT%H:%M:%S%z')
|
||
|
template = "+++\ntitle = '{}'\ndate = {}\nauthor = '{}'\ndraft = True\n+++"
|
||
|
output = template.format(args.title, date, args.author)
|
||
|
if args.verbose: print(template)
|
||
|
|
||
|
# time to write the file :3
|
||
|
with open(args.output, "w+") as file:
|
||
|
if args.verbose: print("Writing to {}...".format(args.output))
|
||
|
file.write(output)
|
||
|
print("Finished writing file to {}".format(args.output))
|
||
|
|
||
|
print("Done.")
|