Skip to content

Commit

Permalink
Merge pull request #76 from shivam5522/main
Browse files Browse the repository at this point in the history
Added join_group(url) to the group.py as per #53
  • Loading branch information
NavpreetDevpuri committed Jan 13, 2021
2 parents 5b87fc7 + c24843e commit 59990f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion tithiwa/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class SELECTORS(object):
# GROUPS__EXIT_DIALOG_BOX_EXIT_BUTTON = (By.CSS_SELECTOR, 'div[class^="overlay"] div[role="button"]:nth-child(2)')
# GROUPS__NO_LONGER_A_PARTICIPANT = (By.CSS_SELECTOR, '._3ge3i')
GROUPS__NAME_IN_CHATS = (By.CSS_SELECTOR, '#side div[aria-label^="Chat list"] div > span[dir="auto"][title]')
GROUPS__GROUP_ICON_IN_POP_UP = (By.CSS_SELECTOR, '.overlay span[data-testid="default-group"]')
GROUPS__JOIN_BUTTON = (By.CSS_SELECTOR, '.overlay div[role="button"]:nth-child(2)')
SETTINGS__OK_BUTTON = (By.CSS_SELECTOR, 'div[class^="overlay"] div[role="button"]:nth-child(2)')
SETTINGS__THEME = (By.CSS_SELECTOR, 'div[title="Theme"]')
SETTINGS__NOTIFICATIONS = (By.CSS_SELECTOR, 'div[title="Notifications"]')
Expand All @@ -77,7 +79,7 @@ class INTEGERS(object):
TURN_OFF_NOTIFICATIONS_FOR_8_HOURS = 0
TURN_OFF_NOTIFICATIONS_FOR_1_WEEK = 1
TURN_OFF_NOTIFICATIONS_FOR_ALWAYS = 2
DEFAULT_WAIT = 13
DEFAULT_WAIT = 89


_SETUP_SESSION = '''
Expand Down
21 changes: 20 additions & 1 deletion tithiwa/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,26 @@ def _wait_for_group_info_to_load(self):
except:
pass

# create_group('yeh', ["Navpreet Devpuri"])
def join_group(self, url, _shouldoutput=(True, True)):
if _shouldoutput[0] and DEFAULT_SHOULD_OUTPUT:
print(f'joining group from link: "{url}"', end="... ")
group_code = url[url.rfind("/") + 1:]
group_url = f'https://web.whatsapp.com/accept?code={group_code}'
self.browser.get(group_url)
self._wait_for_web_whatsapp_to_load()
race_result = self._race_for_presence_of_two_elements(SELECTORS.GROUPS__GROUP_ICON_IN_POP_UP,
SELECTORS.CHATROOM__NAME)
if race_result[1] == 0:
pop_up = self._wait_for_presence_of_an_element(SELECTORS.GROUPS__GROUP_ICON_IN_POP_UP)
self._wait_for_an_element_to_be_clickable(SELECTORS.GROUPS__JOIN_BUTTON).click()
self._wait_for_an_element_to_deattached(pop_up)
if _shouldoutput[0] and DEFAULT_SHOULD_OUTPUT:
print(f'{STRINGS.CHECK_CHAR} Done')
else:
if _shouldoutput[1] and DEFAULT_SHOULD_OUTPUT:
print(f'{STRINGS.CHECK_CHAR} You already joined it. Done')

# create_group('yeh', ["Navpreet Devpuri"])

# print(scrape_members_from_group("PROGRAMMING"))
#
Expand Down
1 change: 1 addition & 0 deletions tithiwa/temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# tithiwabot.generate_session("00")

tithiwabot.open_session()
tithiwabot.join_group('https://chat.whatsapp.com/IxPJXSkqrwK0MGNAk8cZg7')
print()

session = tithiwabot.browser.execute_script("return window.localStorage;")
4 changes: 2 additions & 2 deletions tithiwa/waobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _open_whatsapp_if_not_opened(self):
self.browser.get("https://web.whatsapp.com/")

def _wait_for_web_whatsapp_to_load(self):
self._wait_for_presence_of_an_element(SELECTORS.TURN_ON_DESKTOP_NOTIFICATIONS)
self._wait_for_presence_of_an_element(SELECTORS.MAIN_SEARCH_BAR)

def _wait_for_presence_of_an_element(self, selector):
element = None
Expand Down Expand Up @@ -102,7 +102,7 @@ def _wait_for_an_element_to_deattached(self, element):
pass

def _race_for_presence_of_two_elements(self, selector1, selector2):
selector1orselector2 = selector1 + ", " + selector2
selector1orselector2 = (By.CSS_SELECTOR, selector1[1] + ", " + selector2[1])
winnerelement = self._wait_for_presence_of_an_element(selector1orselector2)
element1 = None
try:
Expand Down

0 comments on commit 59990f8

Please sign in to comment.