Show overdue plants first

Demo ID
cc9df263bdac68228b3c4188ab153e6a52bbabcfd40f99662fabd96fa84998eb
Author
Demo Author
Date
2026-11-15T20:30:00Z
Parent
2e511dc8b44c
Files
Browse this revision

Demo commit. Sort by how overdue each plant is and mark the ones that need water now.

2 changed files

modified README.md view file

@@ -3,3 +3,6 @@
3 Sample project for the Pebble browser demo. Not a real project.
4
5 Usage: python garden.py
6 +
7 + Plants with days since watering > every_days are listed first as
8 + "WATER NOW". Add a plant as a new line: <name>,<room>,<date>,<days>

modified garden.py view file

@@ -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}")