-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
automator.py
90 lines (83 loc) · 3.34 KB
/
automator.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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
from urllib.parse import quote
import os
options = Options()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_argument("--profile-directory=Default")
options.add_argument("--user-data-dir=/var/tmp/chrome_user_data")
os.system("")
os.environ["WDM_LOG_LEVEL"] = "0"
class style():
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
WHITE = '\033[37m'
UNDERLINE = '\033[4m'
RESET = '\033[0m'
print(style.BLUE)
print("**********************************************************")
print("**********************************************************")
print("***** ******")
print("***** THANK YOU FOR USING WHATSAPP BULK MESSENGER ******")
print("***** This tool was built by Anirudh Bagri ******")
print("***** www.github.com/anirudhbagri ******")
print("***** ******")
print("**********************************************************")
print("**********************************************************")
print(style.RESET)
f = open("message.txt", "r", encoding="utf8")
message = f.read()
f.close()
print(style.YELLOW + '\nThis is your message-')
print(style.GREEN + message)
print("\n" + style.RESET)
message = quote(message)
numbers = []
f = open("numbers.txt", "r")
for line in f.read().splitlines():
if line.strip() != "":
numbers.append(line.strip())
f.close()
total_number=len(numbers)
print(style.RED + 'We found ' + str(total_number) + ' numbers in the file' + style.RESET)
delay = 30
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
print('Once your browser opens up sign in to web whatsapp')
driver.get('https://web.whatsapp.com')
input(style.MAGENTA + "AFTER logging into Whatsapp Web is complete and your chats are visible, press ENTER..." + style.RESET)
for idx, number in enumerate(numbers):
number = number.strip()
if number == "":
continue
print(style.YELLOW + '{}/{} => Sending message to {}.'.format((idx+1), total_number, number) + style.RESET)
try:
url = 'https://web.whatsapp.com/send?phone=' + number + '&text=' + message
sent = False
for i in range(3):
if not sent:
driver.get(url)
try:
click_btn = WebDriverWait(driver, delay).until(EC.element_to_be_clickable((By.XPATH, "//button[@data-testid='compose-btn-send']")))
except Exception as e:
print(style.RED + f"\nFailed to send message to: {number}, retry ({i+1}/3)")
print("Make sure your phone and computer is connected to the internet.")
print("If there is an alert, please dismiss it." + style.RESET)
else:
sleep(1)
click_btn.click()
sent=True
sleep(3)
print(style.GREEN + 'Message sent to: ' + number + style.RESET)
except Exception as e:
print(style.RED + 'Failed to send message to ' + number + str(e) + style.RESET)
driver.close()