Skip to content

Instantly share code, notes, and snippets.

@louisswarren louisswarren/
Last active Oct 15, 2019

What would you like to do?
Daily logging made easier with a simple python script

Friday 11th October 2019

A typical Friday

Keywords: logging, programming, overcast

I made a simple script for writing daily logs. This could be useful for taking notes regarding daily progress. This could have been valuable while doing my PhD. Oh well.

The weather isn't great today. Not terrible, just not great.

#!/usr/bin/env python3
import sys
import datetime
usage = '''
mkentry [-]
mkentry [-] <day>
mkentry [-] <month> <day>
mkentry [-] <year> <month> <day>
mkentry --help
Make a journal entry for the given day in the past, writing either to the
appropriate file or stdout.
template = '''
## {date}
##### Title
*Keywords: None*
Text here.
def get_date(*xs):
now =
y = xs[-3] if len(xs) >= 3 else now.year
m = xs[-2] if len(xs) >= 2 else now.month
d = xs[-1] if len(xs) >= 1 else
return, m, d)
def human_day(date):
suffixes = {1: 'st', 21: 'st', 31: 'st',
2: 'nd', 22: 'nd',
3: 'rd', 23: 'rd'}
return str( + suffixes.get(, 'th')
def date_nice_format(date):
fmt = '{0:%A} {human_day} {0:%B} {0:%Y}'
return fmt.format(date, human_day=human_day(date))
def make_entry(date):
return template.format(date=date_nice_format(date))
if __name__ == '__main__':
if len(sys.argv) > 1 and sys.argv[1] == '--help':
date = get_date(*map(int, sys.argv[1:]))
if date >
prompt = date.isoformat() + " is in the future. Continue? [y/N] "
if input(prompt).lower() not in ('y', 'yes'):
with open(date.isoformat() + '.md', 'x') as f:
except FileExistsError:
sys.exit("Entry already exists for {}.".format(date.isoformat()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.