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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
import os,time,datetime
from os import listdir
from os.path import isfile, join
import re
PATH = '/Users/******/Documents/Blog-drafts'
PATH2 = '/Users/******/Documents/Blog'
PATH3 = '/Users/******/Documents/Blog/source/_posts/'
filename = "NAN"
####################################################
onlyfiles = [f for f in listdir(PATH) if isfile(join(PATH, f))]
for f in onlyfiles:
if f[-3:] == ".md":
filename = f[:-3]
if(filename == "NAN"):
print("未找到.md文件,请重试!")
exit(0)
##############################################
file0 = PATH+"/"+filename+".md"
file = open(file0)
wholestring= ""
cnt = 0
for i in file:
if cnt == 0:
i = i.strip()
tags = re.split(',| |,',i)
cnt+=1
else:
wholestring+=i
file.close()
########################################
fileCreatTime = str(datetime.datetime.fromtimestamp(os.stat(file0).st_ctime))
fileModTime = str(datetime.datetime.fromtimestamp(os.stat(file0).st_mtime))
os.system(f"rm {file0}")
text = f'''---
title: {filename}
date: {fileCreatTime[:-7]}
tags:
'''
# if fileCreatTime[:-7] != fileModTime[:-7] :
# text+=f'''
# update: {fileModTime[:-7]}
# '''
#
#
# text+='''
# tags:
# '''
#######################
for i in tags:
text+=f''' - {i}
'''
#######################
text+=f'''
---
'''
###################
print(text)
os.system(f"cd {PATH2} && hexo new {filename}")
PATH3filename = PATH3 + filename.replace('.','-')
with open(f"{PATH3filename}.md","w") as lastfile:
lastfile.write(text)
lastfile.write(wholestring)
lastfile.close()
########################
os.system(f"mv {PATH}/* {PATH3filename}/")
os.system(f"cd {PATH2} && hexo g -d")
|