-
Notifications
You must be signed in to change notification settings - Fork 0
/
makepost.py
44 lines (43 loc) · 1.16 KB
/
makepost.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
40
41
42
43
44
#-*_coding:utf8-*-
#!/usr/bin/python
import sys
import os
import time
import platform
import glob
fileName = ''
if len(sys.argv) > 1:
fileName = sys.argv[1]
if fileName == '':
file_list = glob.glob('*.md')
if len(file_list)!=2:
print('Usage: ./makepost.py <filename>')
exit()
if file_list[0]=="README.md":
fileName=file_list[1]
else:
fileName=file_list[0]
output = ''
output += '---\n'
output += 'layout: post\n'
output += 'title: %s\n' % (os.path.basename(fileName)[:-3])
formatTime = time.strftime("%Y-%m-%d %H:%M:%S +0800", time.localtime())
output += 'date: ' + formatTime + '\n'
ver = platform.python_version()
print(fileName)
if ver[0] == '2':
postTags = raw_input("Please input the tags of this article:")
else:
postTags = input("Please input the tags of this article:")
if postTags=="":
postTags="杂"
output += 'tag: [' + postTags + ']\n'
output += '---\n\n'
f = open(fileName, encoding="utf8")
output += f.read()
f.close()
outFileName = '_posts/' + \
time.strftime("%Y-%m-%d-", time.localtime()) + os.path.basename(fileName)
f = open(outFileName, 'w', encoding='utf8')
f.write(output)
os.remove(fileName)