def scheduled_job(driver, names):
    global has_updates, match_start_time, match_end_time

    current_time = TimeUtils.get_current_time()
    LOGGER.debug_with_time("Entered scheduled_job...")

    # the match hasn't started yet...
    if not properties.IS_TEST_MODE and current_time < match_start_time or current_time > match_end_time:
        return

    has_updates = True
    message_content = get_match_info()

    if not has_updates:
        message_content = "No new updates right now..."

    try:
        for name in names:
            user = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located(
                    (By.XPATH, "//span[@title = \"{}\"]".format(name))))

            LOGGER.debug_with_time("User found!")
            user.click()

            message_box = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located(
                    (By.CLASS_NAME, properties.MESSAGE_BOX_CLASS_NAME)))

            LOGGER.debug_with_time("Message box found!")

            if len(message_content) == 0:
                continue

            message_box.send_keys(message_content)
            LOGGER.debug_with_time("Will wait to locate send_button...")

            send_button = WebDriverWait(driver, 10).until(
                EC.element_to_be_clickable(
                    (By.CLASS_NAME, properties.SEND_BUTTON_CLASS_NAME)))

            LOGGER.debug("Send_button found!")
            send_button.send_keys("\n")
            send_button.click()
    except (TimeoutException, WebDriverException) as e:
        with open(properties.ERROR_LOG_FILE_NAME, "a+") as error_logfile:
            error_logfile.write(
                "ERROR:root:[" +
                TimeUtils.get_current_time().strftime('%Y-%m-%d %H:%M:%S') +
                "] : Exception occurred => " + str(e))

        return
def start_commentary():
    global match_start_time, match_end_time, last_comment

    current_time = TimeUtils.get_current_time()
    match_start_time = current_time.replace(
        hour=properties.MATCH_START_HOURS,
        minute=properties.MATCH_START_MINUTES,
        second=0,
        microsecond=0)
    match_end_time = current_time.replace(hour=properties.MATCH_END_HOURS,
                                          minute=properties.MATCH_END_MINUTES,
                                          second=0,
                                          microsecond=0)
    last_comment = Comment("None", "No comment yet...")
    URL = "https://web.whatsapp.com"

    if (properties.BROWSER.lower() == "safari"):
        driver = webdriver.Safari()
    elif (properties.BROWSER.lower() == "chrome"):
        driver = webdriver.Chrome("../chromedriver")
    elif (properties.BROWSER.lower() == "firefox"):
        driver = webdriver.Firefox()
    else:
        error_message = "Web browser should be one of Safari/Chrome/Firefox"
        LOGGER.error_with_time(error_message)

        return

    driver.get(URL)

    user_input = input(
        "Enter the names of the groups/users you want to text, separated by commas(Eg. - Arya Stark, Sansa Stark, Jon Snow, Bran, Rickon, Robb) : "
    )
    names = [x.strip() for x in user_input.split(',')]
    scheduler(driver, names)
Exemple #3
0
 def __init__(self, device_type, udid, mode, config_file):
     self.device_type = device_type
     self.udid = udid
     self.__udid_validate()
     self.mode = mode
     self.config_file = config_file
     self.exe_id = TimeUtils.get_current_time_for_output()
     self.start_time = TimeUtils.get_current_time()
     self.rule = self.__rule()
     self.driver = self.__driver_router()
     self.flow = self.__flow_router()
     self.cache_file_name = self.__cache_file_name()
     self.window_info = self.driver.window_info
def test_send_messages_on_whatsapp():
    global match_start_time
    global last_comment

    current_time = TimeUtils.get_current_time()
    match_start_time = current_time.replace(
        hour=properties.MATCH_START_HOURS,
        minute=properties.MATCH_START_MINUTES,
        second=0,
        microsecond=0)
    last_comment = Comment("None", "No comment yet...")
    # URL = "https://web.whatsapp.com"

    # driver = webdriver.Safari()
    # driver.get(URL)

    # user_input = input("Enter the names of the groups/users you want to text, separated by commas(Eg. - Arya Stark, Sansa Stark, Jon Snow, Bran, Rickon, Robb) : ")
    # names = [x.strip() for x in user_input.split(',')]

    test_scheduled_job()