-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuto.py
More file actions
170 lines (132 loc) · 5.53 KB
/
Copy pathAuto.py
File metadata and controls
170 lines (132 loc) · 5.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import pandas as pd
import time
import re
import pyautogui
import pyperclip
import random
# ==============================================================
# CONFIG — edit these values before running
# ==============================================================
RESUME_PATH = r"C:\Users\User\Documents\Resume.pdf" # <-- Change this to your resume path
CONTACTS_CSV = "clean_contacts.csv"
MESSAGE_TEMPLATE = """Hello {name},
I'm a B.Tech student, currently in my 8th semester, specializing in cybersecurity. I recently completed the Security+ (SY0-701) certification and have worked on a phishing email detection project, along with an internship in NCR Voyex where I worked with the InfoSec Team.
I'm currently preparing for entry-level roles like SOC Analyst / Security Analyst, and I wanted to ask if you could guide me on what skills or areas I should focus on to become industry-ready.
I would really appreciate your advice.
Thanks for your time
"""
# Delay between contacts in seconds (min, max) — avoids WhatsApp rate limiting
DELAY_BETWEEN_CONTACTS = (8, 15)
# ==============================================================
def get_driver():
options = Options()
options.add_argument("--incognito")
options.add_argument("--start-maximized")
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
return webdriver.Chrome(options=options)
def load_contacts(csv_path):
"""Load and clean contacts from CSV. Returns list of (name, number) tuples."""
df = pd.read_csv(csv_path, header=None, names=["name", "number"])
contacts = []
for _, row in df.iterrows():
name = str(row["name"]).strip()
number = str(row["number"]).strip()
if not name or name.lower() == "nan":
name = "Sir"
number = re.sub(r"\D", "", number)
if len(number) == 10:
number = "91" + number
elif len(number) == 12 and number.startswith("91"):
pass
else:
print(f"⚠️ Skipping invalid number: {number}")
continue
contacts.append((name, number))
print(f"✅ Loaded {len(contacts)} valid contacts")
return contacts
def send_message(driver, wait, name, message):
"""Type and send the text message."""
input_box = wait.until(
EC.presence_of_element_located(
(By.XPATH, '//div[@contenteditable="true"][@data-tab="10"]')
)
)
input_box.click()
time.sleep(1)
for line in message.split("\n"):
input_box.send_keys(line)
input_box.send_keys(Keys.SHIFT, Keys.ENTER)
time.sleep(1)
input_box.send_keys(Keys.ENTER)
print(f" ✅ Message sent")
def send_resume(driver, wait, resume_path):
"""Attach and send the resume PDF via the Document picker."""
# Click the + attach button
attach_btn = wait.until(
EC.presence_of_element_located(
(By.XPATH, '//span[@data-icon="plus-rounded"]/..')
)
)
driver.execute_script("arguments[0].click();", attach_btn)
# Click Document in the attach menu — opens Windows file picker
doc_btn = wait.until(
EC.element_to_be_clickable((By.XPATH, '//button[@aria-label="Document"]'))
)
doc_btn.click()
print(" 📂 Document picker opened")
time.sleep(2)
# Paste the file path directly into the Windows file picker
pyperclip.copy(resume_path)
pyautogui.hotkey('ctrl', 'a')
pyautogui.hotkey('ctrl', 'v')
time.sleep(0.5)
pyautogui.press('enter')
print(" 📄 File path submitted")
time.sleep(3)
# Click the Send button in the WhatsApp preview dialog
send_btn = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.XPATH, '//div[@aria-label="Send"]'))
)
driver.execute_script("arguments[0].click();", send_btn)
print(" 📤 Resume sent!")
def main():
driver = get_driver()
driver.get("https://web.whatsapp.com")
input("Press Enter when WhatsApp is fully loaded and all chats are visible. If not, wait until it loads...")
time.sleep(10)
wait = WebDriverWait(driver, 30)
contacts = load_contacts(CONTACTS_CSV)
success, failed = 0, 0
for i, (name, number) in enumerate(contacts, 1):
print(f"\n[{i}/{len(contacts)}] Processing: {name} ({number})")
driver.get(f"https://web.whatsapp.com/send?phone={number}")
# Send text message
try:
message = MESSAGE_TEMPLATE.format(name=name)
send_message(driver, wait, name, message)
except Exception as e:
print(f" ❌ Message failed: {e}")
failed += 1
continue
# Send resume
try:
send_resume(driver, wait, RESUME_PATH)
success += 1
except Exception as e:
print(f" ❌ Resume failed: {e}")
failed += 1
# Random delay before next contact
delay = random.uniform(*DELAY_BETWEEN_CONTACTS)
print(f" ⏳ Waiting {delay:.1f}s...")
time.sleep(delay)
print(f"\n🎉 Done! Success: {success} | Failed: {failed}")
driver.quit()
if __name__ == "__main__":
main()