upcoming2posts

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.


In [78]:
!git pull


Already up-to-date.

In [79]:
import datetime
from datetime import timedelta
import os
import glob
import re

In [ ]:


In [80]:
today = datetime.date.today()
yesterday = today - timedelta(1)

In [81]:
if yesterday.isoweekday() == 2:
    yesterday_str = yesterday.strftime("%Y-%m-%d")

In [82]:
filename = glob.glob("_posts/" + yesterday_str + "*")[0]

In [83]:
with open(filename, "r") as file:
    file_text = file.read()
file_text


Out[83]:
'---\nlayout: post\ntitle: Spring Break -- no meeting\ncomments: true\ncategory: upcoming\ntags: meeting <+ tags +>\n---\n\n\n'

In [84]:
file_text = file_text.replace('category: upcoming', 'category: posts')
file_text = file_text.replace('category:upcoming', 'category: posts')
file_text


Out[84]:
'---\nlayout: post\ntitle: Spring Break -- no meeting\ncomments: true\ncategory: posts\ntags: meeting <+ tags +>\n---\n\n\n'

In [85]:
with open(filename, "w") as file:
    file.write(file_text)

In [86]:
!git commit -a -m "upcoming to posts [automated]"


[master fa90fef] upcoming to posts [automated]
 1 file changed, 1 insertion(+), 1 deletion(-)

In [ ]:
# note that you have to have credentials set up to push from a notebook, otherwise you do it manually
!git push

In [ ]: