From 2141dae7e590ec3f33e294bc60c2c5875aefd055 Mon Sep 17 00:00:00 2001 From: DuckRodgers <53906002+DuckRodgers@users.noreply.github.com> Date: Wed, 28 Oct 2020 22:11:50 -0300 Subject: [PATCH] Added method that sends msg to contact list Added a method that takes a list of contacts as input and sends the same standard message to all of them. --- whatsapp_api.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/whatsapp_api.py b/whatsapp_api.py index d19d204..884fb8d 100644 --- a/whatsapp_api.py +++ b/whatsapp_api.py @@ -16,6 +16,10 @@ class WhatsApp: + + if __name__ == '__main__': + main() + def __init__(self): self.driver = self._setup_driver() self.driver.get(WP_LINK) @@ -92,4 +96,24 @@ def get_last_message(self): all_messages = self.get_all_messages() return all_messages[-1] + def zap_to_list(self, contact_list): + + def search_contact(self, keyword): + '''Write and send message''' + self._click(NEW_CHAT) + self._send_keys(SEARCH_CONTACT, keyword) + sleep(1) + try: + self._click(FIRST_CONTACT) + except Exception as e: + print("Contact not found") + + def send_message(self, message): + '''Write and send message''' + self.write_message(message) + self._click(SEND) + standard_message = input('Type your message: ') + for contact in contact_list: + do = search_contact(self, contact) + msg = send_message(self,standard_message) \ No newline at end of file