-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchat.py
More file actions
107 lines (90 loc) · 2.88 KB
/
chat.py
File metadata and controls
107 lines (90 loc) · 2.88 KB
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
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 time import sleep
import threading
def encrypt_decrypt(key):
key_list = list(key)
encryp_decryp_key = ""
for i in key_list:
if(ord(i)>=65 and ord(i)<=90 ):
i = chr(65+90-ord(i))
elif(ord(i)>=97 and ord(i)<=122 ):
i = chr(122+97-ord(i))
encryp_decryp_key = encryp_decryp_key + i
return encryp_decryp_key
def send(driver):
while(1):
try:
tx_key = input()
if (ord(list(tx_key)[0]) == 27):
break
message = driver.find_elements_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')[0]
encryp_key = encrypt_decrypt(tx_key)
# encryp_key = tx_key : Uncomment this if you Don't Want To Use Personal Encryption
message.send_keys(encryp_key)
sendbutton = driver.find_elements_by_xpath('//*[@id="main"]/footer/div[1]/div[3]/button')[0]
sendbutton.click()
except:
print("Cannot Send Message. So exiting")
break
def chat(driver):
try:
target_chat = input("Chat Name ??? ")
if (ord(list(target_chat)[0]) == 27):
driver.close()
return
target = '"' + target_chat + '"'
group_title = wait.until(EC.presence_of_element_located((By.XPATH, '//span[contains(@title,' + target + ')]' )))
group_title.click()
except:
print("Could not Find the Chat")
return
else:
value = 10;
tx = threading.Thread(target=send, args=(driver,))
tx.start()
while(1):
try:
msg_old = driver.find_elements_by_xpath('//div[contains(@class,"copyable-text")]')
inbox = driver.find_elements_by_xpath("//span[@class='selectable-text invisible-space copyable-text']")
if (value>2):
for i in range(len(inbox)):
rx_key = inbox[i].text
decryp_key = encrypt_decrypt(rx_key)
# decryp_key = rx_key : Uncomment this if you Don't Want To Use Personal Encryption
print("From : ", msg_old[i].get_attribute("data-pre-plain-text"), "in", target_chat, "is : ", decryp_key)
elif(value==2):
rx_key = inbox[len(inbox) - 1].text
decryp_key = encrypt_decrypt(rx_key)
print("From : ", msg_old[len(inbox) - 1].get_attribute("data-pre-plain-text"), "with", target, "is : ", decryp_key)
sleep(1)
msg_new = driver.find_elements_by_xpath('//div[contains(@class,"copyable-text")]')
if(msg_new != msg_old):
value = 2
else:
value = 1
except:
print("Closing Chat")
return 0
if(not tx.isAlive()):
print("Chat Quit")
return 1
break
if __name__ == "__main__":
try:
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver')
driver.get("https://web.whatsapp.com/")
wait = WebDriverWait(driver, 600)
status = 1
except:
print("Could Not Open Whatsapp Web")
else:
while(status):
try:
status = chat(driver)
except:
print("Closing Whatsapp")
driver.close()
break