Skip to content

Instantly share code, notes, and snippets.

@tomato42
Last active Apr 11, 2018
Embed
What would you like to do?
Quick logging and reporting of performed tasks from this and last week
#!/bin/bash
MYDIR=~/.local/share/idid
mkdir -p "$MYDIR"
echo $(date -u --iso-8601=seconds) $@ >> "$MYDIR"/log
#!/bin/python
from __future__ import print_function
import io
import sys
from dateutil import parser, relativedelta
import datetime
import pytz
import os.path
import textwrap
MYDIR="~/.local/share/idid/"
FILE="log"
path = os.path.expanduser(MYDIR + FILE)
tasks = []
with io.open(path, 'r', encoding='utf-8') as fp:
for line in fp:
datestring, text = line.split(' ', 1)
text = text.strip()
text = "\n".join(textwrap.wrap(
text, width=75,
initial_indent=' * ',
subsequent_indent=' ',
break_long_words=False))
date = parser.parse(datestring)
now = datetime.datetime.now(pytz.UTC)
start = now - datetime.timedelta((now.weekday() + 1) % 7)
if sys.argv[1:2] == ["last"]:
last_sun = start + \
relativedelta.relativedelta(weekday=relativedelta.SU(-2))
next_sun = start + \
relativedelta.relativedelta(weekday=relativedelta.SU(-1))
else:
last_sun = start + \
relativedelta.relativedelta(weekday=relativedelta.SU(-1))
next_sun = start + \
relativedelta.relativedelta(weekday=relativedelta.SU(2))
if last_sun < date < next_sun:
tasks.append(text)
print("* Tasks completed: {0}".format(len(tasks)))
for i in tasks:
print("{0}".format(i))
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment