MCPcopy
hub / github.com/InstaPy/InstaPy / get_following_status

Function get_following_status

instapy/follow_util.py:22–93  ·  view source on GitHub ↗

Verify if you are following the user in the loaded page

(
    browser, track, username, person, person_id, logger, logfolder
)

Source from the content-addressed store, hash-verified

20
21
22def get_following_status(
23 browser, track, username, person, person_id, logger, logfolder
24):
25 """Verify if you are following the user in the loaded page"""
26 if person == username:
27 return "OWNER", None
28
29 if track == "profile":
30 ig_homepage = "https://www.instagram.com/"
31 web_address_navigator(browser, ig_homepage + person)
32
33 follow_button_XP = read_xpath(get_following_status.__name__, "follow_button_XP")
34 failure_msg = "--> Unable to detect the following status of '{}'!"
35 user_inaccessible_msg = (
36 "Couldn't access the profile page of '{}'!\t~might have changed the"
37 " username".format(person)
38 )
39
40 # check if the page is available
41 valid_page = is_page_available(browser, logger)
42 if not valid_page:
43 logger.warning(user_inaccessible_msg)
44 person_new = verify_username_by_id(
45 browser, username, person, None, logger, logfolder
46 )
47 if person_new:
48 ig_homepage = "https://www.instagram.com/"
49 web_address_navigator(browser, ig_homepage + person_new)
50 valid_page = is_page_available(browser, logger)
51 if not valid_page:
52 logger.error(failure_msg.format(person_new.encode("utf-8")))
53 return "UNAVAILABLE", None
54 else:
55 logger.error(failure_msg.format(person.encode("utf-8")))
56 return "UNAVAILABLE", None
57
58 # wait until the follow button is located and visible, then get it
59 try:
60 browser.find_element(
61 By.XPATH, read_xpath(get_following_status.__name__, "follow_button_XP")
62 )
63 follow_button_XP = read_xpath(get_following_status.__name__, "follow_button_XP")
64 except NoSuchElementException:
65 try:
66 follow_button = browser.find_element(
67 By.XPATH,
68 read_xpath(get_following_status.__name__, "follow_span_XP_following"),
69 )
70 return "Following", follow_button
71 except:
72 return "UNAVAILABLE", None
73 follow_button = explicit_wait(
74 browser, "VOEL", [follow_button_XP, "XPath"], logger, 7, False
75 )
76
77 if not follow_button:
78 browser.execute_script("location.reload()")
79 update_activity(browser, state=None)

Callers 6

follow_userFunction · 0.85
unfollow_userFunction · 0.85
verify_actionFunction · 0.85
get_links_for_usernameFunction · 0.85
get_followersFunction · 0.85
get_followingFunction · 0.85

Calls 8

sleepFunction · 0.90
web_address_navigatorFunction · 0.85
read_xpathFunction · 0.85
is_page_availableFunction · 0.85
verify_username_by_idFunction · 0.85
explicit_waitFunction · 0.85
update_activityFunction · 0.85
execute_scriptMethod · 0.80

Tested by

no test coverage detected