Exemplo n.º 1
0
    def soft_block_bots(self, threshold=None):
        """Soft-blocks every bot account classified by Botometer lower than the
        `threshold` (defaults to 0.75 in User class)."""
        total = self.me.followers_count
        to_block = []
        cache = Cache("soft_block_bots", threshold)

        bar_kwargs = dict(
            length=total,
            label=f"Looking for bots in {total} accounts",
            width=0,  # 0 means full-width
        )
        with click.progressbar(**bar_kwargs) as bar:
            for user in self.followers:
                should_soft_block = cache.get(user.screen_name)

                if should_soft_block is None:  # nothing cached
                    should_soft_block = user.is_bot()
                    cache.set(user.screen_name, should_soft_block)

                if should_soft_block:
                    to_block.append(user)

                bar.update(1)

        for user in to_block:
            self.soft_block_bot(user)
Exemplo n.º 2
0
    def unfollow_inactive_for(self, **kwargs):
        """Takes any kwarg compatible with Python's `timedelta` and unfollows
        users whose last tweet are older than the `timedelta` defined by these
        kwargs"""
        total = self.me.friends_count
        to_unfollow = []
        cache = Cache("unfollow_inactive_for", kwargs)

        bar_kwargs = dict(
            length=total,
            label=f"Looking for inactive users in {total} accounts",
            width=0,  # 0 means full-width
        )
        with click.progressbar(**bar_kwargs) as bar:
            for user in self.following:
                should_unfollow = cache.get(user.screen_name)

                if should_unfollow is None:  # nothing cached
                    should_unfollow = user.last_status_before(**kwargs)
                    cache.set(user.screen_name, should_unfollow)

                if should_unfollow:
                    to_unfollow.append(user)

                bar.update(1)

        for user in to_unfollow:
            self.unfollow(user)
Exemplo n.º 3
0
    def soft_block_bots(self, threshold=None):
        """Soft-blocks every bot account classified by Botometer lower than the
        `threshold` (defaults to 0.75 in User class)."""
        total = self.me.followers_count
        to_block = []
        cache = Cache("soft_block_bots", threshold)

        kwargs = self.progress_bar_kwargs("bots", total)
        with click.progressbar(**kwargs) as bar:
            for user in self.followers:
                should_soft_block = cache.get(user.screen_name)

                if should_soft_block is None:  # nothing cached
                    should_soft_block = user.is_bot()
                    cache.set(user.screen_name, should_soft_block)

                if should_soft_block:
                    to_block.append(user)

                bar.update(1)

        for user in to_block:
            self.soft_block_bot(user)
Exemplo n.º 4
0
    def unfollow_inactive_for(self, **kwargs):
        """Takes any kwarg compatible with Python's `timedelta` and unfollows
        users whose last tweet are older than the `timedelta` defined by these
        kwargs"""
        total = self.me.friends_count
        to_unfollow = []
        cache = Cache("unfollow_inactive_for", kwargs)

        kwargs = self.progress_bar_kwargs("inactivity", total)
        with click.progressbar(**kwargs) as bar:
            for user in self.following:
                should_unfollow = cache.get(user.screen_name)

                if should_unfollow is None:  # nothing cached
                    should_unfollow = user.last_status_before(**kwargs)
                    cache.set(user.screen_name, should_unfollow)

                if should_unfollow:
                    to_unfollow.append(user)

                bar.update(1)

        for user in to_unfollow:
            self.unfollow(user)