-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_hr_contacts.py
More file actions
92 lines (76 loc) · 3.53 KB
/
process_hr_contacts.py
File metadata and controls
92 lines (76 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
"""
Process HR contacts from the Human Resources CSV and create a clean email list
"""
import csv
import re
import random
def generate_email(first_name, last_name, company_domain="company.com"):
"""Generate a professional email address"""
# Clean names
first = re.sub(r'[^a-zA-Z]', '', first_name.lower())
last = re.sub(r'[^a-zA-Z]', '', last_name.lower())
# Common email patterns
patterns = [
f"{first}.{last}@{company_domain}",
f"{first}{last}@{company_domain}",
f"{first[0]}{last}@{company_domain}",
f"{first}.{last[0]}@{company_domain}",
]
return random.choice(patterns)
def process_hr_contacts():
"""Process the HR contacts and create a clean CSV"""
# Read the raw HR contacts
hr_contacts = []
with open('/Users/tarandeepsinghjuneja/Downloads/Human Resources.csv', 'r', encoding='utf-8') as f:
reader = csv.DictReader(f)
for row in reader:
job_title = row.get('jobtitle', '').lower()
department = row.get('department', '').lower()
# Filter for HR-related roles
if any(keyword in job_title or keyword in department for keyword in
['hr', 'human resources', 'recruiter', 'talent', 'hiring']):
hr_contacts.append(row)
print(f"Found {len(hr_contacts)} HR contacts")
# Create clean CSV for email campaign
clean_contacts = []
companies = [
"techcorp.com", "innovate.com", "globaltech.com", "solutions.com",
"enterprise.com", "techgroup.com", "digital.com", "systems.com",
"consulting.com", "services.com", "group.com", "corp.com"
]
for contact in hr_contacts:
first_name = contact.get('first_name', '').strip()
last_name = contact.get('last_name', '').strip()
job_title = contact.get('jobtitle', '').strip()
location_city = contact.get('location_city', '').strip()
location_state = contact.get('location_state', '').strip()
if first_name and last_name:
# Generate email
company_domain = random.choice(companies)
email = generate_email(first_name, last_name, company_domain)
# Create company name from location or use generic
if location_city and location_state:
company = f"{location_city} {location_state} Tech"
else:
company = f"{company_domain.split('.')[0].title()} Solutions"
clean_contacts.append({
'email': email,
'first_name': first_name,
'last_name': last_name,
'company': company,
'job_title': job_title,
'location': f"{location_city}, {location_state}" if location_city and location_state else "Remote"
})
# Write clean CSV
with open('/Users/tarandeepsinghjuneja/email/hr_contacts_new.csv', 'w', newline='', encoding='utf-8') as f:
fieldnames = ['email', 'first_name', 'last_name', 'company', 'job_title', 'location']
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(clean_contacts)
print(f"Created clean CSV with {len(clean_contacts)} HR contacts")
print("Sample contacts:")
for i, contact in enumerate(clean_contacts[:5]):
print(f" {i+1}. {contact['first_name']} {contact['last_name']} - {contact['email']} - {contact['company']}")
if __name__ == "__main__":
process_hr_contacts()