Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Feb 23rd, 2018 62 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. from pathlib import Path
  5. import datetime
  6. import frontmatter
  7.  
  8. posts_root = os.environ['HOME'] / Path('dev/brainblog/content/post')
  9.  
  10. for post in posts_root.iterdir():
  11.     fname_date = post.name[0:10] # capture the "2018-02-08" "timestamp" from the post filename
  12.     tstamp = datetime.datetime.strptime(fname_date, "%Y-%m-%d").timestamp()
  13.     utc_time = datetime.datetime.utcfromtimestamp(tstamp)
  14.     utc_string = utc_time.strftime("%Y-%m-%dT%H:%M:%S.%f+00:00")
  15.     with post.open('r') as f:
  16.         post_fm = frontmatter.load(f)
  17.         if not post_fm.get('date'):
  18.             post_fm.__setitem__('date', utc_string)
  19.             post_fm.__setitem__('modified', utc_string)
  20.             post_str = frontmatter.dumps(post_fm)
  21.             f.close()
  22.  
  23.             with post.open('w') as f:
  24.                 f.write(post_str)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top