-
Notifications
You must be signed in to change notification settings - Fork 13
/
create.py
32 lines (27 loc) · 847 Bytes
/
create.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
import argparse
import sys
parser=argparse.ArgumentParser()
parser.add_argument('--date', help='Date in the format of: YYYY-MM--DD')
parser.add_argument('--title', help='Title in the form of: this-is-the-tile')
args=parser.parse_args()
if not args.title:
print 'Please provide a title, use --help for help'
sys.exit()
if not args.date:
print 'Please provide a date, use --help for help'
sys.exit()
directory = "_drafts/blog/{0}/".format(args.date)
if not os.path.exists(directory):
os.makedirs(directory)
f = open("{0}{1}-{2}.md".format(directory, args.date, args.title), "w+")
lines = [
"---",
"title: '{0}'".format(args.title.capitalize()).replace("-", " "),
"layout: post",
"date: '2018-06-06 00:30:00 -0300'",
"---",
"Here goes the content"
]
f.writelines("\n".join(lines))
f.close()