I am using session.like_by_tags() method to like photos. I would like to know whether there is a way to restrict more than one photo from the same user from being liked in the same session.
It traverses the photos with the mentioned hashtag and likes irrespective of whether a photo from the same user has already been liked or not.
If this feature is not available, can this is been considered a feature request as this can result in reduced server calls?
I encountered the same issue and came up with a "quick and dirty" workaround in order to not attempt to like/interact with the same user during a session.like_by_tags()
call:
in instapy.py
in function like_by_tags()
:
in the very beginning of like_by_tags()
, initialize an empty list with the other initializations:
restricted_users=[]
...then deeper down in the function where it's looping through the post links just do the following basic check before calling like_image()
:
if validation != True:
self.logger.info(details)
not_valid_users += 1
continue
else:
web_adress_navigator(self.browser, link)
# ------------------------------------------------------------ #
# ------------------------------------------------------------ #
## customized check to not target a user more than once
if (user_name in restricted_users):
print('\n\n')
print('user already interacted with recently: '+user_name)
print('getting next link...')
print('\n\n')
continue
else:
print('\n\n')
print('user will be interacted with: '+user_name)
print('\n\n')
restricted_users.append(user_name)
# ------------------------------------------------------------ #
# ------------------------------------------------------------ #
#try to like
liked = like_image(self.browser,
user_name,
self.blacklist,
self.logger,
self.logfolder)
...
The print()
statements can obviously be removed
It's not very sophisticated, but it works!
The above mentioned scenario also happens when people post "giant images" spanning over multiple posts.
@hotdogcannon thank you very much for this solution, do you know if it's already merged ? and if it is working for the comment function? cheers
@amauryleproux - it should also prevent commenting that originates from any like_by_tags()
call because commenting happens further down in the inner (links/posts) loop in like_by_tags()
function, so the continue
statement will cause the (links/posts) loop to skip over the commenting part.
I have been playing around with a few improvements and customizations for my own sake lately, but haven't gotten around to submitting a nice 'clean' pull request after merging this into a freshly pulled master yet. I will do so once I have a bit more free time starting in about a week.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. > If this problem still occurs, please open a new issue
Most helpful comment
I encountered the same issue and came up with a "quick and dirty" workaround in order to not attempt to like/interact with the same user during a
session.like_by_tags()
call:in
instapy.py
in functionlike_by_tags()
:in the very beginning of
like_by_tags()
, initialize an empty list with the other initializations:...then deeper down in the function where it's looping through the post links just do the following basic check before calling
like_image()
:The
print()
statements can obviously be removedIt's not very sophisticated, but it works!