Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- from pathlib import Path
- import datetime
- import frontmatter
- posts_root = os.environ['HOME'] / Path('dev/brainblog/content/post')
- for post in posts_root.iterdir():
- fname_date = post.name[0:10] # capture the "2018-02-08" "timestamp" from the post filename
- tstamp = datetime.datetime.strptime(fname_date, "%Y-%m-%d").timestamp()
- utc_time = datetime.datetime.utcfromtimestamp(tstamp)
- utc_string = utc_time.strftime("%Y-%m-%dT%H:%M:%S.%f+00:00")
- with post.open('r') as f:
- post_fm = frontmatter.load(f)
- if not post_fm.get('date'):
- post_fm.__setitem__('date', utc_string)
- post_fm.__setitem__('modified', utc_string)
- post_str = frontmatter.dumps(post_fm)
- f.close()
- with post.open('w') as f:
- f.write(post_str)
Add Comment
Please, Sign In to add comment