-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewpost.py
39 lines (30 loc) · 1.09 KB
/
newpost.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
33
34
35
36
37
38
39
#!/usr/bin/python2
import os
import sys
import time
#POST_PATH = "/path/to/your/posts/location/"
def main(argv):
try:
postTitle = argv[1]
postCategory = argv[2]
except:
postTitle = "DEFAULT TITLE"
postCategory = "DEFAULT CATEGORY"
todayDate = time.strftime('%Y-%m-%d',time.localtime(time.time()))
currentTime = time.strftime('%H:%M',time.localtime(time.time()))
fileNameWithoutDate = postTitle.lower().replace(' ', '-')
fileName = todayDate + "-" + fileNameWithoutDate + ".markdown"
# fileFullName = os.path.join(POST_PATH, fileName)
with open(fileName, 'w+') as fin:
fin.write("---\n")
fin.write("layout: post\n")
fin.write('title: "%s"\n' % postTitle)
fin.write('date: %s %s\n' %(todayDate, currentTime))
fin.write("comments: true\n")
fin.write('categories: %s\n' % postCategory.capitalize())
fin.write("---\n\n\n\n")
fin.write("<!--more-->\n\n\n")
fin.close()
print('"%s" was created successfully.' % fileName)
if __name__ == "__main__":
main(sys.argv)