Tithibots / tithiwa

Automate Web WhatsApp with selenium in python.
MIT License
24 stars 22 forks source link

Solution to Issue#28 #86

Closed ghostrider22 closed 2 years ago

ghostrider22 commented 2 years ago

(Solution to Issue #28)The following methods were added to Chatroom class :- _get_online_status() get_online_status_of(nameornumber) _track_online_status() track_online_status_of(nameornumber)

Program tries to find element 'online' for checking online-offline status. I have edited constants.py to add a CSS selector because, no CSS selector was present for 'online'. When program opens a chat, due to internet speed whatsapp takes time to show whether a person is online or not, so by default I wanted to wait for presence of 'online' maximum upto 3 seconds but the available method _wait_for_presence_of_an_element() by default waits till 89 seconds. So, I have added another method called _check_for_presence_of_an_element() which also take seconds as argument, so as to keep max waiting time to 3seconds. Now method will return true as soon as the online status appears, and if online status doesn't appears, method will wait maximum upto 3 seconds before returning false.

While writing online offline status to a file, I wanted the function to write online status every second, so I passed 1 second as max waiting time in _check_for_presence_of_an_element(), now method would try to find 'online' for 1 second and after that it writes '0' to the file, but if the user is online, _check_for_presence_of_an_element() doesn't wait for 1second and returns element as soon as it finds 'online'. Thus it used to write many '1' in a single second when someone was online. So, I have added a sleep(1) before writing to file, so that program is forced to wait for one second even if it has found the 'online' status. Thus program writes single '1' for every second a user had been online.

NavpreetDevpuri commented 2 years ago

Fixed

  1. file is opening and closing every second
  2. saved time alongside with 1 or 0
  3. saved time with nameornumber filename
  4. checking for the presence of an element sounds like we are just checking whether or not the given element is present or not