Track watering dates
- Demo ID
26a9252661017b12c582a57d1028028228d4c5f50c0cd4bd23bdccf3c6a37a49- Author
- Demo Author
- Date
- 2026-11-04T18:40:00Z
- Parent
-
acdf1782ce8c - Files
- Browse this revision
2 changed files
- modified garden.py
- modified plants.csv
modified garden.py
view file
| @@ -1,5 +1,6 @@ | ||
| 1 | - | """Print the plants in plants.csv (demo).""" |
| 1 | + | """Show how many days since each plant was watered (demo).""" |
| 2 | import csv | |
| 3 | + | from datetime import date |
| 4 | ||
| 5 | ||
| 6 | def load(path="plants.csv"): | |
| @@ -7,5 +8,7 @@ | ||
| 8 | return list(csv.DictReader(f)) | |
| 9 | ||
| 10 | ||
| 11 | + | today = date.today() |
| 12 | for plant in load(): | |
| 11 | - | print(plant["name"]) |
| 13 | + | days = (today - date.fromisoformat(plant["watered"])).days |
| 14 | + | print(f"{plant['name']}: {days} days") |
modified plants.csv
view file
| @@ -1,4 +1,4 @@ | ||
| 1 | - | name,room |
| 2 | - | fern,bathroom |
| 3 | - | basil,kitchen |
| 4 | - | snake plant,hall |
| 1 | + | name,room,watered,every_days |
| 2 | + | fern,bathroom,2026-11-01,3 |
| 3 | + | basil,kitchen,2026-11-03,2 |
| 4 | + | snake plant,hall,2026-10-20,14 |