Skip to content

Instantly share code, notes, and snippets.

@AnthonyWharton
Created December 19, 2017 21:46
Show Gist options
  • Save AnthonyWharton/9a45a6c3a5dd029437836c35aa7383f1 to your computer and use it in GitHub Desktop.
Save AnthonyWharton/9a45a6c3a5dd029437836c35aa7383f1 to your computer and use it in GitHub Desktop.
Makes a blank template for week-daily markdown notes.
#!/bin/python3
import os.path
import inquirer
from calendar import monthrange
from datetime import datetime
ys = range(datetime.now().year-5, datetime.now().year+6)
ys = list(map(lambda y: str(y).zfill(4), ys))
ms = range(1,13)
ms = list(map(lambda m: str(m).zfill(2), ms))
# Options for pickle files
questions = [inquirer.List('yyyy',
message='Select a Year',
choices=ys,
default=str(datetime.now().year)),
inquirer.List('mm',
message='Enter the Month',
choices=ms,
default=str(datetime.now().month))
]
answers = inquirer.prompt(questions)
yyyy = answers['yyyy']
mm = answers['mm']
_, days = monthrange(int(yyyy),int(mm))
if os.path.exists('./'+yyyy+'-'+mm+'.md'):
raise IOError('This file already exists, aborting...')
f = open('./'+yyyy+'-'+mm+'.md', 'w')
for dd in range(1, 1+days):
if 0 <= datetime(int(yyyy), int(mm), dd).weekday() <= 4:
f.write('# '+yyyy+'-'+mm+'-'+str(dd)+'\n\n---\n')
f.write('\n')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment