|
def follow_by_tags(self, |
|
tags=None, |
|
amount=50, |
|
media=None, |
|
skip_top_posts=True, |
|
use_smart_hashtags=False): |
|
if self.aborting: |
|
return self |
|
|
|
inap_img = 0 |
|
followed = 0 |
|
|
|
# if smart hashtag is enabled |
|
if use_smart_hashtags is True and self.smart_hashtags is not []: |
|
print('Using smart hashtags') |
|
tags = self.smart_hashtags |
|
|
|
# deletes white spaces in tags |
|
tags = [tag.strip() for tag in tags] |
|
|
|
tags = tags or [] |
|
|
|
time_break = random.randint(7, 14) |
|
follow_counter = 0 |
|
|
|
for index, tag in enumerate(tags): |
|
self.logger.info('Tag [{}/{}]'.format(index + 1, len(tags))) |
|
self.logger.info('--> {}'.format(str(tag.encode('utf-8'))[self.bye_b])) |
|
|
|
try: |
|
links = get_links_for_tag(self.browser, |
|
tag, |
|
amount, |
|
self.logger, |
|
media, |
|
skip_top_posts) |
|
except NoSuchElementException: |
|
self.logger.error('Too few images, skipping this tag') |
|
continue |
|
|
|
for i, link in enumerate(links): |
|
self.logger.info('[{}/{}]'.format(i + 1, len(links))) |
|
self.logger.info(link) |
|
|
|
try: |
|
inappropriate, user_name, is_video, reason = ( |
|
check_link(self.browser, |
|
link, |
|
self.dont_like, |
|
self.ignore_if_contains, |
|
self.ignore_users, |
|
self.username, |
|
self.like_by_followers_upper_limit, |
|
self.like_by_followers_lower_limit, |
|
self.logger, |
|
self.bye_b) |
|
) |
|
|
|
if not inappropriate: |
|
followed += follow_user(self.browser, |
|
self.follow_restrict, |
|
self.username, |
|
user_name, |
|
self.blacklist, |
|
self.logger, |
|
self.logfolder) |
|
else: |
|
self.logger.info( |
|
'--> User not followed: {}'.format(str(reason.encode('utf-8'))[self.bye_b])) |
|
inap_img += 1 |
|
|
|
follow_counter = followed if followed>follow_counter else follow_counter |
|
if (followed != 0 and |
|
follow_counter==followed and |
|
followed % time_break == 0) : |
|
follow_counter += 1 |
|
time_break = random.randint(7, 14) #reset time break value |
|
nap = random.randint(427, 600) |
|
self.logger.info("I've followed {} users, gonna sleep some {} minutes".format(followed, ceil(nap/60))) |
|
sleep (nap) |
|
|
|
|
|
except NoSuchElementException as err: |
|
self.logger.error('Invalid Page: {}'.format(err)) |
|
|
|
self.logger.info('Inappropriate: {}'.format(inap_img)) |
|
self.logger.info('Followed: {}'.format(followed)) |
|
|
|
self.followed += followed |
|
self.inap_img += inap_img |
|
|
|
return self |
Click on Raw above to copy