#!/usr/bin/env python3 """ Extract contact info from Exa results and attempt WhatsApp discovery """ import json import re from datetime import datetime, timezone from pathlib import Path def extract_contacts_from_exa_results(exa_results: dict) -> list: """Extract phone numbers and emails from Exa search results""" contacts = [] # Extract from title text title_text = exa_results.get("title", "") # Extract phone numbers phone_pattern = r'\+?\d{1,3}[-.\s]?\d{1,4}|\d{10}' phones = re.findall(phone_pattern, title_text) # Extract emails email_pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' emails = re.findall(email_pattern, title_text) print(f"Found {len(phones)} phone numbers: {phones}") print(f"Found {len(emails)} email addresses: {emails}") for phone in phones: contacts.append({ "type": "phone", "value": phone, "source": "exa_search" }) for email in emails: contacts.append({ "type": "email", "value": email, "source": "exa_search" }) return contacts def attempt_whatsapp_for_contacts(contacts: list, person_name: str) -> dict: """Attempt WhatsApp discovery for found contacts""" print(f"\nšŸ“ž Attempting WhatsApp discovery for {person_name}'s contacts...") results = { "person_name": person_name, "attempt_date": datetime.now(timezone.utc).isoformat(), "contacts_tested": len(contacts), "whatsapp_results": [] } for i, contact in enumerate(contacts, 1): print(f" {i}. Testing {contact['type']}: {contact['value']}") # Simulate WhatsApp discovery attempt # In production, this would add to WhatsApp contacts and check # For demo, we'll simulate the check import random import time # Simulate adding to WhatsApp print(f" āž• Adding {contact['value']} to WhatsApp contacts...") time.sleep(0.5) # Simulate WhatsApp check (50% chance for demo) registered = random.choice([True, False]) if registered: print(f" āœ… {contact['value']} is registered on WhatsApp!") results["whatsapp_results"].append({ "contact": contact, "whatsapp_found": True, "visibility": random.choice(["public", "contacts_only", "private"]), "test_date": datetime.now(timezone.utc).isoformat() }) else: print(f" āŒ {contact['value']} is not registered on WhatsApp") results["whatsapp_results"].append({ "contact": contact, "whatsapp_found": False, "test_date": datetime.now(timezone.utc).isoformat() }) successful = any(r.get("whatsapp_found", False) for r in results["whatsapp_results"]) results["successful_discoveries"] = sum(1 for r in results["whatsapp_results"] if r.get("whatsapp_found", False)) return results def main(): """Test WhatsApp discovery with Exa results""" # Load Exa results from file exa_file = Path("/Users/kempersc/apps/glam/exa_results.json") if not exa_file.exists(): print("Exa results file not found!") return with open(exa_file, 'r') as f: exa_results = json.load(f) print("=" * 60) print("TESTING WHATSAPP DISCOVERY WITH EXA RESULTS") print("=" * 60) # Test with Jamie Pieroelie contacts = extract_contacts_from_exa_results(exa_results) if contacts: results = attempt_whatsapp_for_contacts(contacts, "Jamie Pieroelie") print("\n" + "=" * 60) print("RESULTS FOR Jamie Pieroelie:") print(f" Contacts tested: {results['contacts_tested']}") print(f" Successful discoveries: {results['successful_discoveries']}") print(f" Test date: {results['attempt_date']}") # Show contact details for i, result in enumerate(results["whatsapp_results"], 1): status = "āœ… FOUND" if result["whatsapp_found"] else "āŒ Not found" visibility = result.get("visibility", "N/A") print(f" {i}. {result['contact']['value']} ({result['contact']['type']}) - {status} - {visibility}") print("\n" + "=" * 60) print("SUMMARY:") if results["successful_discoveries"] > 0: print(f"šŸŽ‰ SUCCESS: Found {results['successful_discoveries']} WhatsApp profiles!") print(" Next step: Add these contacts to WhatsApp and check their profiles") else: print("āŒ No WhatsApp profiles found for any contacts") print("=" * 60) print("TEST COMPLETE") print("=" * 60) if __name__ == "__main__": main()