forked from rizwansoaib/whatsapp-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
monitor+log.py
116 lines (94 loc) · 4.14 KB
/
monitor+log.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
#!/usr/bin/python3
'''
Author- RIZWAN AHMAD
download https://github.com/mozilla/geckodriver/releases
set path paste binary file /usr/local/bin
sudo apt-get install libnotify-bin espeak
'''
from selenium.webdriver.firefox.options import Options
from selenium import webdriver
import psutil,os
from PIL import Image
from time import strftime,sleep
print("Please Wait Starting whatsapp-monitor")
os.system('notify-send "-i" call-start "Whatsapp Monitor Start" "Developed By RIZWAN AHMAD(rizwansoaib@gmail.com)"')
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
print("QR Code Generating")
driver.get("http://web.whatsapp.com")
def close():
for proc in psutil.process_iter():
if proc.name() == "display":
proc.kill()
with open('qr.png', 'wb') as file:
file.write(driver.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[1]/div/div[2]/div/img').screenshot_as_png)
image = Image.open('qr.png')
print("Sucessfully QR code genereted")
image.show()
log=open('log.txt','a+')
save=False
while True:
try:
chat = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[3]/div/header/div[2]/div/span/div[2]/div")
close()
chat.click()
print("Sucessfully QR Code Scanned")
sleep(2)
save=True
search = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[1]/div/label/input")
search.click()
sleep(2)
name = input("Please enter Contacts name saved in your Phone:>>> ")
search.send_keys(name)
sleep(2)
print("Search Successfully")
open = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/div[1]/span/div/span/div/div[2]/div[1]/div/div/div[2]/div/div")
open.click()
sleep(2)
print("Now tracking is live")
t = strftime("%d/%m/%Y %H:%M:%S")
log.write("==========================={}============================".format(t[:11]))
log.write(" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<{}>>>>>>>>>>>>>>>>>>>>>>>>>> ".format(name))
speako,speakf=True,True
while True:
try:
status = driver.find_element_by_class_name("_315-i").text
t = strftime("%Y-%m-%d %H:%M:%S")
print("{1} : {2} is {0}".format(status, t[11:],name))
if speako and status=='online':
os.system('notify-send "-i" call-start "Whatsapp Monitor" "{2} : {0} is {1} "'.format(name,status,t[11:]))
os.system('espeak -ven-us+f4 -s120 -a 500 "{0} is online in whatsapp"'.format(name))
print("{} : online".format(t[11:])+'\n')
log.write("{}".format(t[11:])+' <<<<<<==Online==>>>>>> ')
speako=False
speakf=True
if status!='online':
speako=True
os.system('notify-send "-i" call-start "Whatsapp Monitor" "{2} : {0} is {1} "'.format(name,status,t[11:]))
os.system('espeak -ven-us+f4 -s120 -a 500 "{0} is {1} in whatsapp"'.format(name,status))
print("{} : {}".format(t[11:],status)+'\n')
log.write("{}".format(t[11:])+'\n')
speakf=True
sleep(1)
except:
status="Offline"
speako=True
t = strftime("%Y-%m-%d %H:%M:%S")
if speakf:
os.system('notify-send "-i" call-start "Whatsapp Monitor" "{2} : {0} is {1} "'.format(name,status,t[11:]))
os.system('espeak -ven-us+f4 -s120 -a 500 "{0} is Offline in whatsapp"'.format(name))
print("{} : offline".format(t[11:])+'\n')
log.write("{} > typing....".format(t[11:])+'\n')
speakf=False
print("{1} : {2} is {0}".format(status, t[11:],name))
sleep(1)
pass
except:
if save:
log.close()
log=open('log.txt','a+')
save=False
print(":Please Scan QR code or something error occured:")
sleep(2)
pass