-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
75 lines (58 loc) · 2.01 KB
/
main.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
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from roll import roll
def envia_msg(msg):
#Sends a Message on an Open chat.
#Envia uma mensagem para a conversa aberta
try:
# Finds the Text Box
# Seleciona a caixa de mensagem
inp_xpath = '//div[@class="_3FRCZ copyable-text selectable-text"][@contenteditable="true"][@data-tab="1"]'
caixa_de_mensagem = driver.find_element_by_xpath(inp_xpath)
# Writes the Message
# Digita a mensagem
caixa_de_mensagem.send_keys(msg)
# Finds the Send Button
# Seleciona botão enviar
botao_enviar = driver.find_element_by_class_name("_1U1xa")
# Sends the Message
# Envia msg
botao_enviar.click()
except Exception as e:
print("Erro ao enviar msg", e)
def ultima_msg():
# Catchs the Last message on the chat.
# Captura a ultima mensagem da conversa.
try:
post = driver.find_elements_by_class_name("_274yw")
ultimo = len(post) - 1
# Get the Text of the Last Message
# O texto da ultima mensagem
texto = post[ultimo].find_element_by_css_selector(
"span.selectable-text").text
return texto
except Exception as e:
print(e)
print("Erro ao ler msg, tentando novamente!")
# Set Here your Chromedriver path.
# Ajuste aqui a localização do seu Chromedriver.
driver = webdriver.Chrome("C:/chromedriver/chromedriver.exe")
driver.get("https://web.whatsapp.com/")
assert "WhatsApp" in driver.title
#print("Connect to You WhatsApp Account")
print("Faça Login Por Favor")
while True:
try:
element = driver.find_element_by_class_name("landing-headerTitle")
except:
break
sleep(5)
#print("Now, open the Group to be monitored.")
print("Agora, Abra o Grupo que deseja Monitorar")
#input("Are you Ready?")
input("Você já Está Pronto?")
while True:
msg = ultima_msg()
if msg[0] == "/":
envia_msg(roll(msg))