Add --where filter to email verifier for targeted scrubs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
justin 2026-05-30 15:06:02 -05:00
parent 97f6a08183
commit 72d1b336c5

View file

@ -166,7 +166,7 @@ def verify_email(email: str) -> tuple[bool, str]:
return True, "mx_unreachable"
def verify_table(table: str, limit: int | None = None, dry_run: bool = False) -> dict:
def verify_table(table: str, limit: int | None = None, dry_run: bool = False, where: str | None = None) -> dict:
"""Verify emails in a database table."""
conn = psycopg2.connect(DATABASE_URL)
cur = conn.cursor()
@ -182,11 +182,13 @@ def verify_table(table: str, limit: int | None = None, dry_run: bool = False) ->
# Get unverified emails
limit_clause = f"LIMIT {limit}" if limit else ""
extra_where = f"AND ({where})" if where else ""
cur.execute(f"""
SELECT dot_number, email_address FROM {table}
WHERE email_address IS NOT NULL
AND email_address != ''
AND (email_verified IS NULL)
{extra_where}
{limit_clause}
""")
@ -247,6 +249,7 @@ def main():
parser.add_argument("--limit", type=int, default=None, help="Limit records")
parser.add_argument("--dry-run", action="store_true", help="Check but don't save")
parser.add_argument("--email", type=str, help="Verify a single email")
parser.add_argument("--where", type=str, default=None, help="Extra SQL WHERE clause (e.g. 'oos_active = TRUE')")
args = parser.parse_args()
if args.email:
@ -254,7 +257,7 @@ def main():
print(f"{args.email}: {'VALID' if is_valid else 'INVALID'} ({reason})")
return
stats = verify_table(args.table, limit=args.limit, dry_run=args.dry_run)
stats = verify_table(args.table, limit=args.limit, dry_run=args.dry_run, where=args.where)
LOG.info("=== Verification Results ===")
for k, v in stats.items():