Created
May 30, 2020 13:22
-
-
Save bopjiang/b47132a97fd32ff99f73174de5bace89 to your computer and use it in GitHub Desktop.
add time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
directory = "/home/XX/Documents/blog-new/content/posts" | |
os.chdir(directory) | |
def do(filename): | |
r = open(filename, 'r') | |
lines = r.readlines() | |
r.close() | |
w = open(filename, 'w') | |
i = 0 | |
dt = filename[:10] | |
for line in lines: | |
if i == 1: | |
w.write("date: %s\n" % (dt)) | |
w.write(line) | |
i+=1 | |
w.close() | |
for filename in os.listdir(directory): | |
if filename.endswith(".md") : | |
do(filename) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment