forked from rizwansoaib/whatsapp-monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
terminal-monitor.py
93 lines (77 loc) · 3.13 KB
/
terminal-monitor.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
#! /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([email protected])"')
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get("http://web.whatsapp.com")
def close():
for proc in psutil.process_iter():
if proc.name() == "display":
proc.kill()
print("QR Code Generating")
sleep(10)
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()
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)
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")
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))
speako=False
speakf=True
if status!='online':
speak=True
os.system('espeak -ven-us+f4 -s120 -a 500 "{0} is Offline in whatsapp"'.format(name))
speakf=False
sleep(1)
except:
status="Offline"
speako=True
if speakf:
os.system('espeak -ven-us+f4 -s120 -a 500 "{0} is Offline in whatsapp"'.format(name))
speakf=False
t = strftime("%Y-%m-%d %H:%M:%S")
print("{1} : {2} is {0}".format(status, t[11:],name))
sleep(1)
pass
except:
print(":Please Scan QR code or something error occured:")
sleep(2)
pass