MCPcopy
hub / github.com/InstaPy/InstaPy / like_image

Function like_image

instapy/like_util.py:736–814  ·  view source on GitHub ↗

Likes the browser opened image

(browser, username, blacklist, logger, logfolder, total_liked_img)

Source from the content-addressed store, hash-verified

734
735
736def like_image(browser, username, blacklist, logger, logfolder, total_liked_img):
737 """Likes the browser opened image"""
738 # check action availability
739 if quota_supervisor("likes") == "jump":
740 return False, "jumped"
741
742 media = "Image" # by default
743 like_xpath = read_xpath(like_image.__name__, "like")
744 unlike_xpath = read_xpath(like_image.__name__, "unlike")
745 play_xpath = read_xpath(like_image.__name__, "play")
746
747 play_elem = browser.find_elements(By.XPATH, play_xpath)
748 if len(play_elem) == 1:
749 # This is because now IG is not only Images, User can share Images and
750 # Videos in one post at the same time, it could be Image -> Video or
751 # Video -> Image so we will try to Like the post like one object.
752 media = "Video"
753 comment = read_xpath(open_comment_section.__name__, "comment_elem")
754 element = browser.find_element(By.XPATH, comment)
755
756 # Now, move until 'Comment' section to determine the status of post
757 # Notice that some videos comes from TikTok and could have larger size
758 # c'est la vie...
759 logger.info("--> Found 'Play' button for a video, trying to like it")
760 browser.execute_script("arguments[0].scrollIntoView(true);", element)
761
762 # find first for like element
763 like_elem = browser.find_elements(By.XPATH, like_xpath)
764
765 if len(like_elem) == 1:
766 # sleep real quick right before clicking the element
767 sleep(2)
768 logger.info("--> {}...".format(media))
769
770 like_elem = browser.find_elements(By.XPATH, like_xpath)
771 if len(like_elem) > 0:
772 click_element(browser, like_elem[0])
773 # check now we have unlike instead of like
774 liked_elem = browser.find_elements(By.XPATH, unlike_xpath)
775
776 if len(liked_elem) == 1:
777 logger.info("--> {} liked!".format(media))
778 Event().liked(username)
779 update_activity(
780 browser, action="likes", state=None, logfolder=logfolder, logger=logger
781 )
782
783 if blacklist["enabled"] is True:
784 action = "liked"
785 add_user_to_blacklist(
786 username, blacklist["campaign"], action, logger, logfolder
787 )
788
789 # get the post-like delay time to sleep
790 naply = get_action_delay("like")
791 sleep(naply)
792
793 # after liking an image we do check if liking activity was blocked

Callers 9

like_by_locationsMethod · 0.85
like_by_tagsMethod · 0.85
like_by_usersMethod · 0.85
interact_by_usersMethod · 0.85
interact_by_URLMethod · 0.85
interact_by_commentsMethod · 0.85
engage_with_postsMethod · 0.85

Calls 11

quota_supervisorFunction · 0.90
read_xpathFunction · 0.85
sleepFunction · 0.85
click_elementFunction · 0.85
EventClass · 0.85
update_activityFunction · 0.85
add_user_to_blacklistFunction · 0.85
get_action_delayFunction · 0.85
verify_liked_imageFunction · 0.85
execute_scriptMethod · 0.80
likedMethod · 0.80

Tested by

no test coverage detected