-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathapplication.py
67 lines (50 loc) · 2.08 KB
/
application.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from selenium import webdriver
import time
PATH="C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://web.whatsapp.com/")
driver.maximize_window()
# Texts which you want to send
text= "Dear "
text2=", He is sleeping right now! He will reply to your texts when he gets up. BTW this is an auto generated reply from his bot. Thanks!"
# Time provided to scan the QR code of Whatsapp Web
time.sleep(10)
# List of names to which you want to send the message
namelist = ["Divyam Kalra","Vivek Raj","Mom"]
while(1):
for name in namelist:
# Click on the search-bar
getsearchbox = driver.find_element_by_xpath("//*[@id='side']/div[1]/div/label/div/div[2]")
getsearchbox.click()
time.sleep(2)
# Type the name of contact
getsearchbox.send_keys(name)
time.sleep(3)
# Check if there is any unread message
unreadMsgs=False
getlist=driver.find_elements_by_xpath("//span[@class ='_31gEB']")
if(len(getlist)):
unreadMsgs=True
# If there is no unread message, then click on back in the search bar
if not unreadMsgs:
cutit=driver.find_element_by_xpath("//*[@id='side']/div[1]/div/button")
cutit.click()
# If an unread message exists, reply to the contact
else:
# Click on the Chat
user=driver.find_element_by_xpath('//span[@title = "{}"]'.format(name))
user.click()
# Type the message on the Chatbox
textbox=driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
textbox.send_keys(text)
textbox.send_keys(name)
textbox.send_keys(text2)
# Send Message
send=driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[3]/button')
send.click()
# Print in contact name in the terminal
print(name,"texted you!")
time.sleep(5)
# The code will run again after 300 seconds (5 Minutes)
time.sleep(300)
driver.quit()