-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwhatsapp_cli.py
116 lines (109 loc) · 3.81 KB
/
whatsapp_cli.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
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
from selenium import webdriver as wbd
import time as t
from datetime import datetime as dtn
def send(driver):
name=raw_input('Enter the contact name or group name\n')
message=raw_input('Enter message\n')
try:
#search=driver.find_element_by_class_name('_2MSJr') # testing for search box
#msg_box.send_keys(name)
#search.click()
#print 'search complete'
user=driver.find_element_by_xpath('//span[@title="{}"]'.format(str(name)))
user.click()
except:
print 'Selected name is not present. Try Again'
return
try:
#print 'user selected'
msg_box= driver.find_element_by_class_name('_3F6QL')
msg_box.click()
#print 'message box clicked'
msg_box.send_keys(message)
#print 'written in message box'
button=driver.find_element_by_class_name('_2lkdt')
button.click()
except:
print 'Message could not be written. Try Again'
def check(driver):
#this facility is working for only last message. will extend it later
name=raw_input('Enter the contact name or group name\n')
user=driver.find_element_by_xpath('//span[@title="{}"]'.format(str(name)))
user.click()
unread=driver.find_element_by_class_name('L89LI')
print unread
return
def log(driver):
name=raw_input('Enter the contact name or group name\n')
try:
user=driver.find_element_by_xpath('//span[@title="{}"]'.format(str(name)))
user.click()
except:
print 'Selected name is not present. Try Again.'
return
tm=input('for how long you want to run the log. Enter in minutes\n')
tm=tm*60
print 'Running log'
fi=str(name)+'.txt'
f=open(fi,'a')
while True:
try:
act=driver.find_element_by_xpath('.//span[@class="{}"]'.format('O90ur'))
if act.text=='click here for contact info':
pass
elif act.text.split(' ')[0]=='last':
temp=act.text.split(' ')
text=str(temp[2])+' '+str(temp[4])+' '+str(temp[5])+'\n'
f2=open(fi,'r')
flag=0
for lines in f2:
if str(lines.strip(' '))==str(text):
flag=1
f2.close()
if flag==0:
f.write(text)
flag=0
if act.text=='online':
#print '{} is online'.format(name)
time=dtn.now().strftime("%Y-%m-%d %H:%M")
f2=open(fi,'r')
flag1=0
for lines in f2:
if str(lines.strip(' '))==str(time):
flag1=1
if flag1==0:
f.write(text)
except:
print '****************************'
print 'User have disabled last seen'
print '****************************'
print
tm=tm-1
t.sleep(1)
print 'Time left: {} secs'.format(tm)
if tm<=0:
f.close()
return
def activity(driver):
print '-----------------------------------------------'
print 'Warning this will only work for recent contacts'
print '-----------------------------------------------'
print
inp=input('Enter your choice\n1.Send Message\n2.Check Messages\n3.Check online log activity\n4.Exit\n')
if inp==1:
send(driver)
elif inp==2:
check(driver)
elif inp==3:
log(driver)
elif inp==4:
exit()
else:
print 'wrong input'
def main():
driver = wbd.Chrome('C:\Users\Program017\Downloads\chromedriver')
driver.get('https://web.whatsapp.com')
while True:
activity(driver)
if __name__=='__main__':
main()