2026-05-12 15:21:06 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
"""
|
2026-07-15 20:11:04 -04:00
|
|
|
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.
|
2026-05-12 15:21:06 -04:00
|
|
|
|
|
|
|
|
Usage:
|
2026-07-15 20:11:04 -04:00
|
|
|
# AWS credentials with bedrock:InvokeModel are only needed if a sample falls
|
|
|
|
|
# back to the AI extractor; pure-template samples parse fully offline.
|
2026-05-12 15:21:06 -04:00
|
|
|
python test_local.py
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
import sys
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent / "lambdas" / "wo" / "email_processor"))
|
|
|
|
|
|
2026-07-15 20:11:04 -04:00
|
|
|
from handler import parse_raw_email, extract_with_bedrock
|
|
|
|
|
from template_parser import try_deterministic_parse
|
2026-05-12 15:21:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2026-07-15 20:11:04 -04:00
|
|
|
print(f"\n{'=' * 80}")
|
2026-05-12 15:21:06 -04:00
|
|
|
print(f"FILE: {eml_path.name}")
|
2026-07-15 20:11:04 -04:00
|
|
|
print(f"{'=' * 80}")
|
2026-05-12 15:21:06 -04:00
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
2026-07-15 20:11:04 -04:00
|
|
|
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})")
|
2026-05-12 15:21:06 -04:00
|
|
|
print(json.dumps(parsed, indent=2))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|