Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Import required packages
- from selenium import webdriver
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.common.by import By
- from selenium.common.exceptions import TimeoutException
- import pickle
- import time
- import os
- # Driver to open a browser
- from selenium.webdriver.chrome.options import Options
- chrome_options = Options()
- chrome_options.add_argument("user-data-dir=selenium")
- driver = webdriver.Chrome('./chromedriver', chrome_options=chrome_options)
- #link to open a site
- driver.get("https://web.whatsapp.com/")
- # 10 sec wait time to load, if good internet connection is not good then increase the time
- # units in seconds
- # note this time is being used below also
- wait = WebDriverWait(driver, 10)
- wait5 = WebDriverWait(driver, 5)
- time.sleep(10)
- try:
- wait5.until(EC.presence_of_element_located((
- By.CLASS_NAME, "landing-title"
- )))
- except TimeoutException:
- print("No need to log in (we think)")
- driver.find_element(By.XPATH, '//span[text()="סופרים עד אינסוף - בינארי"]').click()
- else:
- input("Scan the QR code and then press Enter")
- # if os.path.isfile('cookies.pkl'):
- # with open('cookies.pkl', 'rb') as f:
- # cookies = pickle.load(f)
- # for cookie in cookies:
- # driver.add_cookie(cookie)
- # if not cookies:
- # input("Scan the QR code and then press Enter")
- # with open('cookies.pkl', 'wb') as f:
- # pickle.dump( driver.get_cookies(), f)
- # else:
- # input("Scan the QR code and then press Enter")
- # pickle.dump( driver.get_cookies() , open("cookies.pkl","wb"))
- LAST_NUM = -1
- def send_message():
- global LAST_NUM
- # Click on input box
- inp_xpath = "//div[@contenteditable='true']"
- inputs = driver.find_elements_by_xpath(inp_xpath)
- time.sleep(1)
- # Calculate next number
- all_msgs = driver.find_elements_by_xpath("//span[contains(@class, 'selectable-text') and contains(@class, 'copyable-text') and contains(@class, 'invisible-space')]")
- out_msgs = driver.find_elements_by_class_name('message-out')
- if not out_msgs:
- last_out = False
- else:
- last_out = out_msgs[-1]
- pured_msgs = [x.text for x in all_msgs if not last_out or out_msgs[-1].location['y'] < x.location['y'] and x.text not in out_msgs[-1].text]
- for msg in reversed(pured_msgs):
- try:
- sanitized = msg.replace(' ', '').replace('-', '')
- if sanitized == '=x':
- print(f'Current num is {hex(LAST_NUM)}')
- inputs[1].send_keys(f'{hex(LAST_NUM)}')
- inputs[1].send_keys(Keys.ENTER)
- elif sanitized == '=d':
- print(f'Current num is {LAST_NUM}')
- inputs[1].send_keys(f'{LAST_NUM}')
- inputs[1].send_keys(Keys.ENTER)
- elif sanitized == '=o':
- print(f'Current num is {LAST_NUM}')
- inputs[1].send_keys(f'{oct(LAST_NUM)}')
- inputs[1].send_keys(Keys.ENTER)
- else:
- bin_num = int(sanitized, base=2)
- break
- except ValueError:
- print(f'{msg} is not a binary')
- else:
- print('No bin number found')
- return
- next_num = bin_num+1
- LAST_NUM = next_num
- inputs[1].send_keys(f'{bin(next_num)[2:]}')
- inputs[1].send_keys(Keys.ENTER)
- while True:
- try:
- send_message()
- except:
- pass
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement