Last active
December 30, 2023 18:11
-
-
Save gkbrk/a610af06f5440836aa8f4844c596dec4 to your computer and use it in GitHub Desktop.
Todo.txt to graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import matplotlib.pyplot as plt | |
import datetime | |
def get_stats(filename): | |
data = {} | |
with open(filename) as todofile: | |
for line in todofile: | |
date = line.split()[1] | |
if date in data: | |
data[date] += 1 | |
else: | |
data[date] = 1 | |
return data | |
def get_last_days(days): | |
for day in range(days)[::-1]: | |
date = datetime.datetime.today() - datetime.timedelta(days=day) | |
yield date.date().isoformat() | |
plt.grid(True) | |
plt.title("Todo.txt Progress") | |
plt.ylabel("Number of tasks done") | |
stats = get_stats("/home/leonardo/Sync/default/done.txt") | |
todoCounts = [] | |
for date in get_last_days(15): | |
todoCounts.append(stats.get(date, 0)) | |
plt.yticks(range(max(todoCounts) + 1)) | |
plt.xticks(range(15), get_last_days(15), rotation=80) | |
plt.plot(todoCounts, marker="o") | |
plt.tight_layout() | |
plt.savefig("public/img/todo.jpeg", dpi=100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing! I made some tweaks into your script so that the path could be specified as an argument to the script. Check it out!