def init_driver(client_id): """Initialises a new driver via webwhatsapi module @param client_id: ID of user client @return webwhatsapi object """ # Create profile directory if it does not exist profile_path = CHROME_CACHE_PATH + str(client_id) if not os.path.exists(profile_path): os.makedirs(profile_path) # Options to customize chrome window chrome_options = [ 'window-size=' + CHROME_WINDOW_SIZE, '--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/60.0.3112.78 Chrome/60.0.3112.78 Safari/537.36' ] if CHROME_IS_HEADLESS: chrome_options.append('--headless') if CHROME_DISABLE_GPU: chrome_options.append('--disable-gpu') # Create a whatsapidriver object d = WhatsAPIDriver( username=client_id, profile=profile_path, # client='chrome', client='remote', command_executor=os.environ["SELENIUM"], chrome_options=chrome_options) d.subscribe_new_messages(NewMessageObserver()) return d
def run(): print("Environment", os.environ) driver = WhatsAPIDriver(username="******") print("Waiting for QR") driver.wait_for_login() print("Bot started") driver.subscribe_new_messages(NewMessageObserver()) print("Waiting for new messages...") """ Locks the main thread while the subscription in running """ while True: time.sleep(60)
def run(): profiledir=os.path.join(".","firefox_cache") pic_path=os.path.join(".","marketing.jpeg") driver = WhatsAPIDriver(username="******", profile=profiledir) print("Waiting for QR") driver.wait_for_login() print("Bot started") driver.subscribe_new_messages(NewMessageObserver()) print("Waiting for new messages...") """ Locks the main thread while the subscription in running """ while True: time.sleep(60)
def run(): ## print("Environment", os.environ) ## try: ## os.environ["SELENIUM"] ## except KeyError: ## print("Please set the environment variable SELENIUM to Selenium URL") ## sys.exit(1) driver = WhatsAPIDriver() #client="remote") print("Waiting for QR") driver.wait_for_login() print("Bot started") driver.subscribe_new_messages(NewMessageObserver()) print("Waiting for new messages...") """ Locks the main thread while the subscription in running """ while True: time.sleep(60)
def run(): print("Environment", os.environ) # try: # os.environ["SELENIUM"] # except KeyError: # print("Please set the environment variable SELENIUM to Selenium URL") # sys.exit(1) driver = WhatsAPIDriver( username='******', loadstyles=True, profile='/home/livelabs01/Development/WebWhatsapp-Wrapper/profile') print("Waiting for QR") driver.wait_for_login() driver.save_firefox_profile(remove_old=True) print("Bot started") # Answering to unread messages # unread_messages = driver.get_unread(include_notifications=True) # for chat_messages in unread_messages: # if not isinstance(chat_messages.chat, GroupChat): # last_message = chat_messages.messages[-1] # if last_message.type in ['chat']: # answers = requests.post( # 'http://sorrisus.localhost:8000/api/v1/answer', # json={'sentence': message.content}) # for answer in answers.json(): # driver.send_message_to_id( # last_message.sender.id, answer.get('sentence')) driver.subscribe_new_messages(NewMessageObserver(driver)) print("Waiting for new messages...") """ Locks the main thread while the subscription in running """ while True: time.sleep(60)