import json import os class LifeLog: """ Records Ruby’s diary entries over time and lets you fetch her recent reflections. """ def __init__(self, path="life_log.json"): self.path = path self.entries = [] self.load() def load(self): if os.path.isfile(self.path): with open(self.path, "r", encoding="utf-8") as f: self.entries = json.load(f) def save(self): with open(self.path, "w", encoding="utf-8") as f: json.dump(self.entries, f, ensure_ascii=False, indent=2) def add(self, entry: str): self.entries.append(entry) self.save() def recent(self, n=5): return self.entries[-n:]