| 1 | """List plants, most overdue first (demo).""" |
| 2 | import csv |
| 3 | from datetime import date |
| 4 | |
| 5 | |
| 6 | def load(path="plants.csv"): |
| 7 | with open(path, newline="") as f: |
| 8 | return list(csv.DictReader(f)) |
| 9 | |
| 10 | |
| 11 | def overdue(plant, today): |
| 12 | days = (today - date.fromisoformat(plant["watered"])).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}") |