#!/usr/bin/env python3 """ Local test script - parses sample WO emails through the deterministic template parser, falling back to Claude on Bedrock for anything the templates don't cover. Usage: # AWS credentials with bedrock:InvokeModel are only needed if a sample falls # back to the AI extractor; pure-template samples parse fully offline. python test_local.py """ import json import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent / "lambdas" / "wo" / "email_processor")) from handler import parse_raw_email, extract_with_bedrock from template_parser import try_deterministic_parse def main(): samples_dir = Path(__file__).parent / "samples" eml_files = list(samples_dir.glob("*.eml")) if not eml_files: print("No .eml files found in samples/") return for eml_path in eml_files: print(f"\n{'=' * 80}") print(f"FILE: {eml_path.name}") print(f"{'=' * 80}") raw = eml_path.read_bytes() email_data = parse_raw_email(raw) print(f"Subject: {email_data['subject']}") print(f"From: {email_data['sender']}") print(f"Date: {email_data['date']}") print(f"Body preview: {email_data['body'][:200]}...") print() parsed, method, template_id, reason = try_deterministic_parse(email_data) if parsed is None: print(f"Template miss ({template_id}/{reason}); sending to Bedrock...") parsed = extract_with_bedrock(email_data) method = "ai_fallback" print(f"Parse method: {method} (template={template_id}, reason={reason})") print(json.dumps(parsed, indent=2)) if __name__ == "__main__": main()