#!/usr/bin/python

import sys
import os
import os.path
import datetime

today = datetime.date.today()
date = (today if len(sys.argv) < 2
        # Expecting filename in YYYY-MM-DD.foo format
        else os.path.basename(sys.argv[1].rsplit(".", 1)[0]))
dateobj = datetime.datetime.strptime(date, '%Y-%m-%d')

# Lazy algo
for day in range(1, 8):
    monthday = dateobj.replace(day=day)
    if monthday.weekday() not in [4, 5]:
        break

optional_checklists = ""
if dateobj.weekday() == 0:
    optional_checklists += "* [ ] Review previous week notes"
    # Link previous week notes
    previous = dateobj - datetime.timedelta(days=7)
    while previous.weekday() != 5:
        date = previous.strftime('%Y-%m-%d')
        optional_checklists += f" [{date}](./{date}.md)"
        previous = previous + datetime.timedelta(days=1)

if dateobj.day == monthday.day:
    optional_checklists += "* [ ] Review previous month notes"

print(f"""# {date}

## Daily checklist

* [ ] Check Github notifications
* [ ] Check [status of Github PR's](https://github.com/pulls)
* [ ] [Review requests](https://github.com/pulls/review-requested)
* [ ] Email
{optional_checklists}

## Todo

## Notes""")
