From 835c74098f7d9bdcbb4df1e64f5374e9ec3ef93e Mon Sep 17 00:00:00 2001 From: Rolf Leggewie Date: Sat, 4 Feb 2023 18:32:51 +0100 Subject: [PATCH 1/4] switch to platformdirs. Closes: #104 - add platformdirs python library to runtime dependencies - use platformdirs' magic to determine where to store user data --- alright/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/alright/__init__.py b/alright/__init__.py index 184174d..9830ca6 100644 --- a/alright/__init__.py +++ b/alright/__init__.py @@ -8,6 +8,7 @@ import sys import time import logging +import platformdirs from typing import Optional from pathlib import Path from selenium import webdriver @@ -57,12 +58,11 @@ def __init__(self, browser=None, time_out=600): @property def chrome_options(self): chrome_options = Options() + chrome_options.add_argument("--user-data-dir=" + platformdirs.user_data_dir("alright")) if sys.platform == "win32": chrome_options.add_argument("--profile-directory=Default") - chrome_options.add_argument("--user-data-dir=C:/Temp/ChromeProfile") else: chrome_options.add_argument("start-maximized") - chrome_options.add_argument("--user-data-dir=./User_Data") return chrome_options def cli(self): From 97befd018cb1c257c9bbef875ee47b28c2d2dd85 Mon Sep 17 00:00:00 2001 From: Rolf Leggewie Date: Fri, 27 Jan 2023 15:58:43 +0100 Subject: [PATCH 2/4] nitpick improvement to spelling and wording in __init__.py --- alright/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alright/__init__.py b/alright/__init__.py index 9830ca6..b949378 100644 --- a/alright/__init__.py +++ b/alright/__init__.py @@ -264,7 +264,7 @@ def search_chat_by_name(self, query: str): search_box.send_keys(Keys.ARROW_DOWN) chat = self.browser.switch_to.active_element - # excepcitonally acceptable here! + # acceptable here as an exception! time.sleep(1) flag = False prev_name = "" From 98ef244cec7f1c8b5afa4ee912a3bac9be7c0e5e Mon Sep 17 00:00:00 2001 From: Kalebu Date: Sun, 12 Feb 2023 15:44:52 +0300 Subject: [PATCH 3/4] resolve issue #108 --- alright/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/alright/__init__.py b/alright/__init__.py index b949378..30f96a7 100644 --- a/alright/__init__.py +++ b/alright/__init__.py @@ -58,7 +58,9 @@ def __init__(self, browser=None, time_out=600): @property def chrome_options(self): chrome_options = Options() - chrome_options.add_argument("--user-data-dir=" + platformdirs.user_data_dir("alright")) + chrome_options.add_argument( + "--user-data-dir=" + platformdirs.user_data_dir("alright") + ) if sys.platform == "win32": chrome_options.add_argument("--profile-directory=Default") else: @@ -424,7 +426,7 @@ def send_message1(self, mobile: str, message: str) -> str: ) # Iterate through the list of elements to test each if they are a textBox or a Button for i in ctrl_element: - if i.aria_role == "textbox": + if i.get_attribute("role") == "textbox": # This is a WhatsApp Number -> Send Message for line in message.split("\n"): @@ -438,7 +440,7 @@ def send_message1(self, mobile: str, message: str) -> str: # Found alert issues when we send messages too fast, so I called the below line to catch any alerts self.catch_alert() - elif i.aria_role == "button": + elif i.get_attribute("role") == "button": # Did not find the Message Text box # BUT we possibly found the XPath of the error "Phone number shared via url is invalid." if i.text == "OK": From 5eecc5f722fa94fbf6219d2b8d872a453a4aba05 Mon Sep 17 00:00:00 2001 From: fierylion Date: Tue, 11 Apr 2023 16:11:45 +0300 Subject: [PATCH 4/4] option to create headless chrome --- alright/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/alright/__init__.py b/alright/__init__.py index 30f96a7..5f7ec98 100644 --- a/alright/__init__.py +++ b/alright/__init__.py @@ -29,13 +29,13 @@ class WhatsApp(object): - def __init__(self, browser=None, time_out=600): + def __init__(self, headless=False, browser=None, time_out=600): # CJM - 20220419: Added time_out=600 to allow the call with less than 600 sec timeout # web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}") self.BASE_URL = "https://web.whatsapp.com/" self.suffix_link = "https://web.whatsapp.com/send?phone={mobile}&text&type=phone_number&app_absent=1" - + self.headless= headless if not browser: browser = webdriver.Chrome( ChromeDriverManager().install(), @@ -58,6 +58,7 @@ def __init__(self, browser=None, time_out=600): @property def chrome_options(self): chrome_options = Options() + chrome_options.headless = self.headless chrome_options.add_argument( "--user-data-dir=" + platformdirs.user_data_dir("alright") )