-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsend_msg.py
46 lines (40 loc) · 1.84 KB
/
send_msg.py
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
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
def send_message(t,w,n,c,f):
driver = webdriver.Chrome(c)
driver.get('http://web.whatsapp.com')
name = n
wait = WebDriverWait(driver = driver, timeout = w)
lists = []
with open(f,"r") as f: # set the path acc to ur system
lines = f.readlines()
for line in lines:
line = line.replace("\n","")
lists.append(line)
input('Press any key after scanning QR code')
user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()
input_path = '//div[@class="_2S1VP copyable-text selectable-text"][@data-tab="1"]'#change the div class valu here
msg_box = wait.until(EC.presence_of_element_located((By.XPATH,input_path)))
for k in lists:
msg = k
msg_box.send_keys(msg + Keys.ENTER)
time.sleep(t)
if __name__ == "__main__":
import sys
import argparse
parser = argparse.ArgumentParser(description='automatically sends messages to whatsapp contacts')
parser.add_argument('-t', '--time_out', default=2.0, type=float, help='time out time in seconds after each message')
parser.add_argument('-w', '--wait', default=90.0,type=float,help='specify the waiting time until the textbar of whatsapp is located')
parser.add_argument('-n', '--name', default=None, type=str, help='specify the name of the recipient')
parser.add_argument('-c', '--chrome', default=None, type=str, help='specify the path of chrome driver')
parser.add_argument('-f', '--file', default=None, type=str, help='specify the path of the text file containing the messages')
args = parser.parse_args()
if args.name:
send_message(args.time_out,args.wait,args.name,args.chrome,args.file)
else:
parser.print_help()