Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added create_group() function #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions PyWhatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,45 @@ def send_unsaved_contact_message():
print("Failed to send message exception: ", e)
return

def create_group():
print("Creating Group...")
driver.find_element_by_css_selector('div[title="Menu"]').click()
time.sleep(1)
driver.find_element_by_css_selector('div[aria-label="New group"]').click()
time.sleep(1)
contact = input("Enter name of contact or number to add to create group : ")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use contact.txt list and pick contacts from there or pass a contact list to this create_group function.

driver.find_element_by_css_selector('input[placeholder="Type contact name"]').send_keys(contact)
time.sleep(2)
try:
main_contact_item = driver.find_element_by_css_selector('div[data-testid="contact-list-key"]')
contacts = main_contact_item.find_elements_by_css_selector('._3m_Xw')
print('select a contact to add to group : ')
time.sleep(2)
for i in range(len(contacts)):
time.sleep(0.5)
contactname = contacts[i].find_element_by_xpath(f'/html/body/div[1]/div[1]/div[1]/div[2]/div[1]/span/div[1]/span/div[1]/div/div[2]/div[1]/div/div/div[{str(i+1)}]/div/div/div[2]/div[1]/div/span/span').text
print(f' - {i+1}.{contactname}')
while True:
contact_choice = str(input('\nEnter a choice : '))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the choices?

Copy link
Author

@saisumanthkumar saisumanthkumar Oct 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shauryauppal once you pass the name in ,the filter shows some names we can choose some names these are our choices

if contact_choice.isdigit():
if int(contact_choice) <= len(contacts) and int(contact_choice) > 0:
contacts[int(contact_choice) - 1].click()
time.sleep(1)
break
else:
print('enter the choice range ,only given from above')
else:
print('\nEnter valid option\n')
driver.find_element_by_css_selector('span[data-testid="arrow-forward"]').click()
time.sleep(1)
group_name = input('Enter name of the group : ')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the name of group to function take input in main

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take all inputs in main and keep function simple

driver.find_elements_by_css_selector('div[role="textbox"]')[0].send_keys(group_name)
driver.find_element_by_css_selector('span[data-testid="checkmark-medium"]').click()
time.sleep(1)
print('\nCreating Group...')
print('\nSuccessfully created the group\n')
except :
print('No contact found!!!')

def send_attachment():
# Attachment Drop Down Menu
Expand Down