Exemplo n.º 1
0
	def apply(self):
		logger.info(f'Processing action ({self.__class__.__name__}) for ({self.isp.profile.email})...')
		driver = self.isp.driver
		profile = self.isp.profile

		# print('Start ActionChains...')
		# Go to spam section.
		driver.get('https://mail.yahoo.com/d/folders/6')

		# let javascript requests finish.
		time.sleep(5)

		# Scroll down.
		with utils.scroll_down(driver, 'div[data-test-id=virtual-list]', ignored_exceptions=(JavascriptException,)):
			time.sleep(2)

			total_messages = self.isp.get_total_messages()

			if not isinstance(total_messages, int):
				# set a default value or exit.
				total_messages = 0

			actions = ActionChains(driver)
			# Archive all messages.
			try:
				# scroll top to open the first message.
				with utils.scroll_up(driver, 'div[data-test-id=virtual-list]', ignored_exceptions=(JavascriptException,)):
					messages = driver.find_elements_by_css_selector('a[data-test-id=message-list-item]')
					messages[0].click()
					# get the amount of messages to open.
					last_message = common.get_amount_of_message(total_messages)
					click.secho(f'({profile.email}) Total messages {total_messages}: {last_message} messages will be openned.', fg='bright_black')

					with click.progressbar(length=last_message, label=f'Openning messages ({profile.email})...', show_pos=True) as bar:
						for i in range(last_message):
							actions = ActionChains(driver)
							actions.send_keys(Keys.ARROW_RIGHT)
							# add start to the current message.
							if random.random() <= app_settings.MESSAGES_STARTS_RATIO:
								actions.send_keys('l')
							actions.perform()

							# show the progress
							# print(f'\r{i+1}/{last_message}', end='')

							bar.update(1) # +=1 each time

							# clear the all chained actions (is not working, it's a bug in selenium source code).
							# actions.reset_actions()

							time.sleep(random.uniform(3, 5))


			except TimeoutException:
				logger.warning(f'({self.ACTION.name}) {profile.email:.<40} [WARNING]')
			except Exception as e:
				logger.exception(f'[{self.ACTION.name}] {profile.email:.<40} [Error]')
			else:
				logger.info(f'({self.ACTION.name}) {profile.email:.<40} [DONE]')
Exemplo n.º 2
0
    def apply(self):
        logger.info(
            f'Processing action ({self.__class__.__name__}) for ({self.isp.profile.email})...'
        )
        driver = self.isp.driver
        profile = self.isp.profile

        # print('Start ActionChains...')
        # Go to Junk section
        driver.get('https://mail.yahoo.com/d/folders/6')

        # let javascript requests finish.
        time.sleep(5)

        # Scroll down.
        with utils.scroll_down(driver,
                               'div[data-test-id=virtual-list]',
                               ignored_exceptions=(TimeoutException,
                                                   JavascriptException)):
            actions = ActionChains(driver)
            # select all msgs at spam section.
            actions.key_down(Keys.CONTROL).send_keys('a').key_up(
                Keys.CONTROL).perform()

            time.sleep(5)

            # report all to inbox.
            try:
                button_not_junk = driver.find_elements_by_css_selector(
                    'button[data-test-id=toolbar-not-spam]')[0]
                button_not_junk.click()
                # click to "Not junk" button.

                time.sleep(5)
                wait = WebDriverWait(driver, 30)
                # undo_notification = (By.CSS_SELECTOR, 'div[role=status] div')
                alertdialog = (By.CSS_SELECTOR, 'div[role=alertdialog] div')

                if wait.until_not(EC.presence_of_element_located(alertdialog)):
                    # print('Confirm')
                    # wait to make sure the action is applied
                    time.sleep(5)
            except TimeoutException:
                logger.warning(
                    f'[{self.ACTION.name}] Timeout ({profile.email}).')
            except IndexError:
                logger.warning(
                    f'[{self.ACTION.name}] Maybe no messages are found in Spam of ({profile.email}).'
                )
            except Exception as e:
                logger.exception(f'[{self.ACTION.name}] ({profile.email})')
            else:
                logger.info(
                    f'({self.ACTION.name}) {profile.email:.<40} [DONE]')
Exemplo n.º 3
0
    def apply(self):
        logger.info(
            f'Processing action ({self.__class__.__name__}) for ({self.isp.profile.email})...'
        )
        driver = self.isp.driver
        profile = self.isp.profile

        # print('Start ActionChains...')
        # Go to Inbox section
        driver.get('https://mail.yahoo.com/d/folders/1')

        # let javascript requests finish.
        time.sleep(5)

        # Scroll down.
        with utils.scroll_down(driver,
                               'div[data-test-id=virtual-list]',
                               ignored_exceptions=(JavascriptException, )):
            time.sleep(2)

            total_messages = self.isp.get_total_messages()

            if not isinstance(total_messages, int):
                # set a default value or exit.
                total_messages = 0

            actions = ActionChains(driver)
            # Archive all messages.
            try:
                # scroll top to open the first message.
                with utils.scroll_up(
                        driver,
                        'div[data-test-id=virtual-list]',
                        ignored_exceptions=(JavascriptException, )):
                    messages = driver.find_elements_by_css_selector(
                        'a[data-test-id=message-list-item]')
                    messages[0].click()

                    # get the amount of messages to open.
                    last_message = common.get_amount_of_message(total_messages)
                    click.secho(
                        f'({profile.email}) Total messages {total_messages}: {last_message} messages will be openned.',
                        fg='bright_black')

                    with click.progressbar(
                            length=last_message,
                            label=f'Openning messages ({profile.email})...',
                            show_pos=True) as bar:
                        for i in range(last_message):
                            actions = ActionChains(driver)
                            actions.send_keys(Keys.ARROW_RIGHT)
                            # add start to the current message.
                            if random.random(
                            ) <= app_settings.MESSAGES_STARTS_RATIO:
                                actions.send_keys('l')

                            # perform actions in the chain.
                            actions.perform()
                            time.sleep(1)
                            # click on an image (first image) in the current message.
                            if random.random(
                            ) <= app_settings.MESSAGES_CLICK_RATIO:
                                # driver.execute_script("""
                                # 	let images = document.querySelectorAll("div[data-test-id=message-view-body-content] a img")
                                # 	if (images.length)
                                # 		images[0].click()
                                # """)

                                images_in_messages = driver.find_elements_by_css_selector(
                                    'div[data-test-id=message-view-body-content] a img'
                                )
                                if images_in_messages:
                                    try:
                                        image_to_click = images_in_messages[0]
                                        ActionChains(driver).key_down(
                                            Keys.CONTROL).click(
                                                image_to_click).key_up(
                                                    Keys.CONTROL).perform()
                                        # actions.move_to_element(image_to_click).click(image_to_click)
                                    except WebDriverException:
                                        pass

                            bar.update(1)  # +=1 each time

                            time.sleep(random.uniform(2, 5))

            except TimeoutException:
                logger.warning(
                    f'({self.ACTION.name}) {profile.email:.<40} [WARNING]')
            except Exception as e:
                logger.exception(
                    f'[{self.ACTION.name}] {profile.email:.<40} [Error]')
            else:
                logger.info(
                    f'({self.ACTION.name}) {profile.email:.<40} [DONE]')