#!/usr/bin/env python3
import sys
from datetime import datetime

TEMPLATE = """
---
Title: {title}
Date: {year}-{month}-{day} {hour}:{minute:02d}
Modified: {year}-{month}-{day} {hour}:{minute:02d}
Category: 
Tags: 
Authors: procamora
Slug: {slug}
Summary: 
Status: draft
---
"""


def make_entrymdAntiguo(title):
	today = datetime.today()
	slug = title.lower().strip().replace(' ', '-')
	f_create = "content/draft/{}_{:0>2}_{:0>2}_{}.md".format(
		today.year, today.month, today.day, slug)
	t = TEMPLATE.strip().format(title=title,
								year=today.year,
								month=today.month,
								day=today.day,
								hour=today.hour,
								minute=today.minute,
								slug="{}_{:0>2}_{:0>2}_{}".format(today.year, today.month, today.day, slug))

	with open(f_create, 'w') as w:
		w.write(t)
	print("File created -> " + f_create)

def make_entrymd(title):
	today = datetime.today()
	slug = title.lower().strip().replace(' ', '_').replace(':', '').replace('.','')
	f_create = "content/draft/{}.md".format(slug)
	t = TEMPLATE.strip().format(title=title,
								year=today.year,
								month=today.month,
								day=today.day,
								hour=today.hour,
								minute=today.minute,
								slug=slug)
	with open(f_create, 'w') as w:
		w.write(t)
	print("File created -> " + f_create)

if __name__ == '__main__':

	if len(sys.argv) > 1:
		make_entrymd(sys.argv[1])
	else:
		print("No title given")
