By Stuart Geiger (@staeiou), MIT license
This is a script you run the day after THW, which changes yesterday's file from "upcoming" to "posts" so that the next week's topic shows on the main page.
!git pull
Already up-to-date.
import datetime
from datetime import timedelta
import os
import glob
import re
today = datetime.date.today()
yesterday = today - timedelta(1)
if yesterday.isoweekday() == 2:
yesterday_str = yesterday.strftime("%Y-%m-%d")
filename = glob.glob("_posts/" + yesterday_str + "*")[0]
with open(filename, "r") as file:
file_text = file.read()
file_text
'---\nlayout: post\ntitle: Spring Break -- no meeting\ncomments: true\ncategory: upcoming\ntags: meeting <+ tags +>\n---\n\n\n'
file_text = file_text.replace('category: upcoming', 'category: posts')
file_text = file_text.replace('category:upcoming', 'category: posts')
file_text
'---\nlayout: post\ntitle: Spring Break -- no meeting\ncomments: true\ncategory: posts\ntags: meeting <+ tags +>\n---\n\n\n'
with open(filename, "w") as file:
file.write(file_text)
!git commit -a -m "upcoming to posts [automated]"
[master fa90fef] upcoming to posts [automated] 1 file changed, 1 insertion(+), 1 deletion(-)
# note that you have to have credentials set up to push from a notebook, otherwise you do it manually
!git push