# Optional local-only file example. Run from the course root:
# python examples/05_local_files.py
import csv
from pathlib import Path
root = Path(__file__).resolve().parents[1]
source_path = root / "datasets" / "study_sessions.csv"
with source_path.open(encoding="utf-8", newline="") as source:
rows = list(csv.DictReader(source))
total = sum(int(row["minutes"]) for row in rows)
output_dir = root / "outputs"
output_dir.mkdir(exist_ok=True)
output_path = output_dir / "session_summary.txt"
# This intentionally replaces only this generated output, not the input CSV.
output_path.write_text(f"Accepted minutes: {total}\n", encoding="utf-8")
print(output_path.name, "contains", total, "minutes")