Skip to content

Instantly share code, notes, and snippets.

@johanbove
Created January 27, 2022 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johanbove/03fa8dcf00ea22e6e0e7708b552b3d85 to your computer and use it in GitHub Desktop.
Save johanbove/03fa8dcf00ea22e6e0e7708b552b3d85 to your computer and use it in GitHub Desktop.
Todo.txt file reporter
# Analyses the "Todo.txt" file and returns a report
# More about the Todo.txt format: http://todotxt.org/
#
# Needs: python3
#
# Todo:
# - Check out the library: https://github.com/vonshednob/pytodotxt
#
# COPYLEFT - NO WARRANTIES! - I'M A NOOB LICENSE
# https://pendulum.eustace.io/
import pendulum
# https://pypi.org/project/inflect/
import inflect
## Start the language engine
p = inflect.engine()
# Point this to your todo.txt file
PATH_TODOTXT = '/Users/You/todo.txt'
# Projects to check for in the report
PROJECTS = ['@PROJECT1', '@PROJECT2','@personal']
TZ = 'Europe/Berlin'
with open(PATH_TODOTXT) as f:
lines = f.readlines()
number_of_occurences = 0
DATE_FORMAT = '%Y-%m-%d'
TASKS_OPEN = []
TASKS_DONE = []
TASKS_DUE = []
TASKS_DUE_TODAY = []
TASKS_OVERDUE = []
TODAY = pendulum.today()
for line in lines:
for project in PROJECTS:
for word in line.split():
if word == project:
if (line.startswith('x ') == False):
TASKS_OPEN.append(project)
if ('due:' in line):
line = line.replace('\n','')
theDueDateStr = line[-10:]
theDueDate = pendulum.parse(theDueDateStr + "T00:00:00", tz=TZ)
# print(f"The due date is {theDueDate.strftime(DATE_FORMAT)}")
TASKS_DUE.append(project)
if (theDueDate < TODAY):
TASKS_OVERDUE.append(project)
elif (theDueDate == TODAY):
TASKS_DUE_TODAY.append(project)
else :
TASKS_DONE.append(project)
print(f"=== Todo.txt Report For {TODAY.strftime(DATE_FORMAT)} ===")
for project in PROJECTS:
open = TASKS_OPEN.count(project)
closed = TASKS_DONE.count(project)
due = TASKS_DUE.count(project)
overdue = TASKS_OVERDUE.count(project)
duetoday = TASKS_DUE_TODAY.count(project)
nrOpenTasks = p.plural("todo", open)
nrClosedTasks = p.plural("todo", closed)
if (open > 0 and due > 0):
if (overdue > 0):
isAre = p.plural("is", overdue)
print(f"Project {project} has {open} {nrOpenTasks} of which {overdue} {isAre} overdue!")
elif (duetoday > 0):
isAre = p.plural("is", duetoday)
print(f"Project {project} has {open} {nrOpenTasks} of which {duetoday} {isAre} due today!")
else:
isAre = p.plural("is", duetoday)
print(f"Project {project} has {open} {nrOpenTasks} of which {due} {isAre} due.")
elif (open == 0 and closed == 0):
print(f"Project {project} has no todos.")
else:
print(f"Project {project} has {open} {nrOpenTasks}.")
print("=== Have a nice day! ===")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment