Skip to content

Instantly share code, notes, and snippets.

@emilyhorsman
Last active August 29, 2015 14:20
Show Gist options
  • Save emilyhorsman/0bdd72522793a9f662c2 to your computer and use it in GitHub Desktop.
Save emilyhorsman/0bdd72522793a9f662c2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from datetime import date, timedelta
from os import listdir, stat
from os.path import isfile, join
def colour(t):
c = '\033[94m'
return c + t + '\033[0m'
def days_ago(date):
delta = date - date.today()
delta = abs(delta.days)
if delta == 0:
return "Today"
return "{} day{} ago".format(delta, "s" if delta > 1 else "")
def check_highlights(date, f):
prompt = "Highlight:"
for line in f:
if line[:len(prompt)] != prompt:
continue
print "{}: {}".format(colour(days_ago(date)), line[10:].strip())
f.close()
entry_directory = "entries"
# List of date-filepath tuples sorted by most recent date first.
entries = map(lambda f: join(entry_directory, f), listdir(entry_directory))
entries = map(lambda f: (date.fromtimestamp(stat(f).st_mtime), f), entries)
entries = sorted(entries, reverse=True)
start = date.today() - timedelta(days=7)
for entry in entries:
f = entry[1]
if not isfile(f):
continue
if f[-4:] != ".txt":
continue
if entry[0] > start:
check_highlights(entry[0], open(f, 'r'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment