🔍 Code Extractor

function main_v27

Maturity: 46

Command-line entry point that parses arguments and orchestrates the extraction of vendor emails from all vicebio.com mailboxes using Microsoft Graph API.

File:
/tf/active/vicechatdev/find_email/extract_vendor_batch.py
Lines:
118 - 172
Complexity:
moderate

Purpose

This function serves as the main CLI interface for a vendor email extraction tool. It handles argument parsing for configuration options (vendor file path, mailbox limits, email limits, date ranges, test mode), validates the existence of the vendor Excel file, and delegates to the extract_batch function to perform the actual email extraction. It's designed to be called when running the script directly from the command line.

Source Code

def main():
    """Main entry point"""
    import argparse
    
    parser = argparse.ArgumentParser(
        description="Extract vendor emails from all vicebio.com mailboxes"
    )
    parser.add_argument(
        "--vendor-file",
        default="Vendors list_Vicebio_20112025_VB comments v1_enriched_20251121_225259.xlsx",
        help="Path to vendor Excel file"
    )
    parser.add_argument(
        "--max-mailboxes",
        type=int,
        default=None,
        help="Limit number of mailboxes (for testing)"
    )
    parser.add_argument(
        "--max-emails",
        type=int,
        default=DEFAULT_MAX_EMAILS_PER_MAILBOX,
        help="Max emails per mailbox per vendor"
    )
    parser.add_argument(
        "--days-back",
        type=int,
        default=DEFAULT_DAYS_BACK,
        help="Days to search back"
    )
    parser.add_argument(
        "--test",
        action="store_true",
        help="Test mode: only process first 3 vendors"
    )
    
    args = parser.parse_args()
    
    # Check if vendor file exists
    vendor_file = Path(args.vendor_file)
    if not vendor_file.exists():
        print(f"ERROR: Vendor file not found: {vendor_file}")
        print("\nLooking for enriched vendor files in current directory:")
        for f in Path.cwd().glob("*enriched*.xlsx"):
            print(f"  - {f.name}")
        sys.exit(1)
    
    # Run extraction
    extract_batch(
        vendor_excel_file=str(vendor_file),
        max_mailboxes=args.max_mailboxes,
        max_emails_per_mailbox=args.max_emails,
        days_back=args.days_back,
        test_mode=args.test
    )

Return Value

Returns None implicitly. The function either exits with sys.exit(1) if the vendor file is not found, or completes after calling extract_batch(). Side effects include printing error messages and executing the email extraction workflow.

Dependencies

  • argparse
  • sys
  • pandas
  • pathlib
  • typing
  • vendor_email_extractor
  • vendor_email_config

Required Imports

import sys
import pandas as pd
from pathlib import Path
from typing import List, Optional
from vendor_email_extractor import VendorEmailExtractor
from vendor_email_config import TENANT_ID, CLIENT_ID, CLIENT_SECRET, OPENAI_API_KEY, DOMAIN, DEFAULT_DAYS_BACK, DEFAULT_MAX_EMAILS_PER_MAILBOX

Conditional/Optional Imports

These imports are only needed under specific conditions:

import argparse

Condition: imported lazily inside the function, always needed when main() is called

Required (conditional)

Usage Example

# Run from command line:
# python script.py --vendor-file vendors.xlsx --max-mailboxes 5 --max-emails 100 --days-back 30 --test

# Or call directly in Python:
if __name__ == '__main__':
    main()

# With custom vendor file:
# python script.py --vendor-file /path/to/custom_vendors.xlsx

# Test mode (first 3 vendors only):
# python script.py --test

# Limit mailboxes for testing:
# python script.py --max-mailboxes 2 --max-emails 50

Best Practices

  • Always ensure the vendor Excel file exists before running; the function will list available enriched files if the specified file is not found
  • Use --test flag when first running to validate setup with only 3 vendors
  • Use --max-mailboxes parameter to limit scope during development/testing
  • The function expects extract_batch() to be defined in the same module scope
  • Ensure all configuration constants are properly set in vendor_email_config.py before running
  • The default vendor file path is hardcoded; consider using a more generic default or making it required
  • Function calls sys.exit(1) on error, which terminates the entire Python process
  • Command-line arguments override default values from vendor_email_config module

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function extract_batch 75.5% similar

    Batch processes a list of vendors from an Excel file to extract their email addresses by searching through Microsoft 365 mailboxes using AI-powered email analysis.

    From: /tf/active/vicechatdev/find_email/extract_vendor_batch.py
  • function main_v26 75.3% similar

    Demonstrates example usage of the VendorEmailExtractor class by searching for vendor emails across Office 365 mailboxes and displaying results.

    From: /tf/active/vicechatdev/find_email/vendor_email_extractor.py
  • function main_v14 73.4% similar

    Command-line interface function that orchestrates the enrichment of vendor data from an Excel file with email and VAT information using ChromaDB and RAG engine.

    From: /tf/active/vicechatdev/find_email/vendor_enrichment.py
  • function main_v42 68.8% similar

    Entry point function that parses command-line arguments and orchestrates the FileCloud email processing workflow to find, download, and convert .msg files.

    From: /tf/active/vicechatdev/msg_to_eml.py
  • function run_all_tests 65.6% similar

    Orchestrates a comprehensive test suite for the Vendor Email Extractor system, verifying configuration, authentication, mailbox access, email search, and LLM connectivity.

    From: /tf/active/vicechatdev/find_email/test_vendor_extractor.py
← Back to Browse