Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ def _get_api_key(self) -> str:
api_key = input("Enter your Verimail.io API key: ")
progress.update(task, advance=1, description="[green]API key received", total=1)
return api_key

def _get_exception_names(self) -> List[str]:
"""
Get list of names to skip verification for.

Returns:
List of full names to skip verification
"""
with Progress() as progress:
task = progress.add_task("[cyan]Would you like to add exception names to skip verification?", total=1)
response = input("Would you like to add exception names to skip verification? (yes/no): ").lower()

if response == 'yes':
exceptions = []
self.console.print("[cyan]Enter full names (one per line). Enter a blank line when finished:")
Expand Down Expand Up @@ -326,36 +326,36 @@ def extract_phone_number(self, company_url: str) -> Optional[str]:
self.logger.error(f"Error extracting phone number for {company_url}: {str(e)}")
return None

def _try_alternative_patterns(self, first_name: str, last_name: str, company_url: str,
def _try_alternative_patterns(self, first_name: str, last_name: str, company_url: str,
current_pattern: str) -> Dict[str, Any]:
"""
Try alternative email patterns if current pattern results in hardbounce.

Args:
first_name: First name of the person
last_name: Last name of the person
company_url: URL of the company
current_pattern: Current pattern that failed

Returns:
Dictionary with verification results and pattern attempts info
"""
# Skip current pattern as it was already tried
alternative_patterns = [p for p in self.standard_patterns if p != current_pattern]

# Track patterns attempted
attempted_patterns = [current_pattern]
attempts_count = 1

self.logger.info(f"Trying alternative patterns for {first_name} {last_name} at {company_url}")

# Try each alternative pattern
for pattern in alternative_patterns:
email = self.generate_emails(first_name, last_name, company_url, pattern)
verification_result = self.verify_email(email)
attempted_patterns.append(pattern)
attempts_count += 1

# If we found a valid email, return it
if verification_result.get('valid', False) or \
verification_result.get('result') != 'hardbounce':
Expand All @@ -367,15 +367,15 @@ def _try_alternative_patterns(self, first_name: str, last_name: str, company_url
"attempts_count": attempts_count,
"success": True
}

# Add delay between attempts to avoid rate limiting
time.sleep(random.uniform(1, 2))

# If we get here, all patterns failed
self.logger.warning(f"All email patterns failed for {first_name} {last_name} at {company_url}")
return {
"email": None,
"verification": None,
"verification": None,
"pattern_used": None,
"patterns_attempted": attempted_patterns,
"attempts_count": attempts_count,
Expand Down Expand Up @@ -420,32 +420,32 @@ def _process_row(self, row: pd.Series, index: int) -> Tuple[int, Dict[str, Any]]
# Verify email
elif self.validate_emails:
verification_result = self.verify_email(result['Email'])

# If verification failed with hardbounce, try alternative patterns
if verification_result.get('result') == 'hardbounce':
self.logger.info(f"Hardbounce detected for {result['Email']}, trying alternative patterns")

retry_result = self._try_alternative_patterns(
name.first,
name.last,
row['Company URL'],
name.first,
name.last,
row['Company URL'],
row['Pattern']
)

if retry_result['success']:
# Update with successful pattern
result['Email'] = retry_result['email']
verification_result = retry_result['verification']
result['Pattern'] = retry_result['pattern_used']

# Add retry information
result['Patterns Attempted'] = ', '.join(retry_result['patterns_attempted'])
result['Patterns Count'] = retry_result['attempts_count']
else:
# No retry needed
result['Patterns Attempted'] = row['Pattern']
result['Patterns Count'] = 1

# Store verification results
result['Email Verification'] = verification_result['valid']
result['Verification Status'] = verification_result['status']
Expand Down