| @@ -1,4 +1,4 @@ |
| 1 | - | """Show how many days since each plant was watered (demo).""" |
| 1 | + | """List plants, most overdue first (demo).""" |
| 2 | | import csv |
| 3 | | from datetime import date |
| 4 | | |
| @@ -8,7 +8,13 @@ |
| 8 | | return list(csv.DictReader(f)) |
| 9 | | |
| 10 | | |
| 11 | - | today = date.today() |
| 12 | - | for plant in load(): |
| 11 | + | def overdue(plant, today): |
| 12 | | days = (today - date.fromisoformat(plant["watered"])).days |
| 14 | - | print(f"{plant['name']}: {days} days") |
| 13 | + | return days - int(plant["every_days"]) |
| 14 | + | |
| 15 | + | |
| 16 | + | today = date.today() |
| 17 | + | for plant in sorted(load(), key=lambda p: overdue(p, today), reverse=True): |
| 18 | + | late = overdue(plant, today) |
| 19 | + | flag = "WATER NOW" if late > 0 else "ok" |
| 20 | + | print(f"{plant['name']:<12} {flag}") |