Skip to content

Instantly share code, notes, and snippets.

@bopjiang
Created May 30, 2020 13:22
Show Gist options
  • Save bopjiang/b47132a97fd32ff99f73174de5bace89 to your computer and use it in GitHub Desktop.
Save bopjiang/b47132a97fd32ff99f73174de5bace89 to your computer and use it in GitHub Desktop.
add time
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