def get_and_verify_purchase(purchase_id): """Get purchase and verify it can be updated""" response = requests.get( f"https://api.dcycle.io/v1/purchases/{purchase_id}", headers=headers ) if response.status_code == 404: raise ValueError("Purchase not found") purchase = response.json() if purchase["status"] == "in_progress": raise ValueError("Cannot modify purchase while in progress") return purchase# Verify before updatingpurchase = get_and_verify_purchase("550e8400-e29b-41d4-a716-446655440000")print(f"Current CO2e: {purchase['co2e']} kg")