MCPcopy
hub / github.com/InstaPy/InstaPy / get_active_users

Function get_active_users

instapy/util.py:672–927  ·  view source on GitHub ↗

Returns a list with usernames who liked the latest n posts

(browser, username, posts, boundary, logger)

Source from the content-addressed store, hash-verified

670
671
672def get_active_users(browser, username, posts, boundary, logger):
673 """Returns a list with usernames who liked the latest n posts"""
674
675 user_link = "https://www.instagram.com/{}/".format(username)
676
677 # check URL of the webpage, if it already is user's profile page,
678 # then do not navigate to it again
679 web_address_navigator(browser, user_link)
680
681 try:
682 total_posts = browser.execute_script(
683 "return window._sharedData.entry_data."
684 "ProfilePage[0].graphql.user.edge_owner_to_timeline_media.count"
685 )
686 except WebDriverException:
687 try:
688 topCount_elements = browser.find_elements(
689 By.XPATH, read_xpath(get_active_users.__name__, "topCount_elements")
690 )
691
692 if topCount_elements: # prevent an empty string scenario
693 total_posts = format_number(topCount_elements[0].text)
694 else:
695 logger.info("Failed to get posts count on your profile! ~empty string")
696 total_posts = None
697 except NoSuchElementException:
698 logger.info("Failed to get posts count on your profile!")
699 total_posts = None
700
701 # if posts > total user posts, assume total posts
702 posts = (
703 posts if total_posts is None else total_posts if posts > total_posts else posts
704 )
705
706 active_users = []
707 sc_rolled = 0
708 start_time = time.time()
709 too_many_requests = 0 # helps to prevent misbehaviours when requests
710 # list of active users repeatedly within less than 10 min of breaks
711
712 message = (
713 "~collecting the entire usernames from posts without a boundary!\n"
714 if boundary is None
715 else "~collecting only the visible usernames from posts without scrolling "
716 "at the boundary of zero..\n"
717 if boundary == 0
718 else "~collecting the usernames from posts with the boundary of {}"
719 "\n".format(boundary)
720 )
721 # posts argument is the number of posts to collect usernames
722 logger.info(
723 "Getting active users who liked the latest {} posts:\n {}".format(
724 posts, message
725 )
726 )
727
728 count = 1
729 checked_posts = 0

Callers 1

Calls 10

web_address_navigatorFunction · 0.85
read_xpathFunction · 0.85
format_numberFunction · 0.85
click_elementFunction · 0.85
sleep_actualFunction · 0.85
update_activityFunction · 0.85
get_users_from_dialogFunction · 0.85
progress_trackerFunction · 0.85
close_dialog_boxFunction · 0.85
execute_scriptMethod · 0.80

Tested by

no test coverage detected