MCPcopy
hub / github.com/InstaPy/InstaPy / follow_user

Function follow_user

instapy/unfollow_util.py:538–630  ·  view source on GitHub ↗

Follow a user either from the profile page or post page or dialog box

(browser, track, login, user_name, button, blacklist, logger, logfolder)

Source from the content-addressed store, hash-verified

536
537
538def follow_user(browser, track, login, user_name, button, blacklist, logger, logfolder):
539 """Follow a user either from the profile page or post page or dialog box"""
540 # list of available tracks to follow in: ["profile", "post dialog"]
541
542 # check action availability
543 if quota_supervisor("follows") == "jump":
544 return False, "jumped"
545
546 if track in ["profile", "post"]:
547 # if track == "profile":
548 # check URL of the webpage, if it already is user's profile
549 # page, then do not navigate to it again
550 user_link = "https://www.instagram.com/{}/".format(user_name)
551 web_address_navigator(browser, user_link)
552
553 # find out CURRENT following status
554 following_status, follow_button = get_following_status(
555 browser, track, login, user_name, None, logger, logfolder
556 )
557 if following_status in ["Follow", "Follow Back"]:
558 click_visibly(browser, follow_button) # click to follow
559 follow_state, msg = verify_action(
560 browser, "follow", track, login, user_name, None, logger, logfolder
561 )
562 if follow_state is not True:
563 return False, msg
564
565 elif following_status in ["Following", "Requested"]:
566 if following_status == "Following":
567 logger.info("--> Already following '{}'!\n".format(user_name))
568
569 elif following_status == "Requested":
570 logger.info("--> Already requested '{}' to follow!\n".format(user_name))
571
572 sleep(1)
573 return False, "already followed"
574
575 elif following_status in ["Unblock", "UNAVAILABLE"]:
576 if following_status == "Unblock":
577 failure_msg = "user is in block"
578
579 elif following_status == "UNAVAILABLE":
580 failure_msg = "user is inaccessible"
581
582 else:
583 # Trace the current status
584 failure_msg = following_status
585
586 logger.warning(
587 "--> Couldn't follow '{}'!\t~{}".format(user_name, failure_msg)
588 )
589 return False, following_status
590
591 elif following_status is None:
592 sirens_wailing, emergency_state = emergency_exit(browser, login, logger)
593 if sirens_wailing is True:
594 return False, emergency_state
595

Callers 13

follow_through_dialogFunction · 0.85
follow_by_listMethod · 0.85
like_by_locationsMethod · 0.85
comment_by_locationsMethod · 0.85
like_by_tagsMethod · 0.85
like_by_usersMethod · 0.85
interact_by_usersMethod · 0.85
follow_by_locationsMethod · 0.85
follow_by_tagsMethod · 0.85
interact_by_URLMethod · 0.85

Calls 15

quota_supervisorFunction · 0.90
web_address_navigatorFunction · 0.85
get_following_statusFunction · 0.85
click_visiblyFunction · 0.85
verify_actionFunction · 0.85
sleepFunction · 0.85
emergency_exitFunction · 0.85
click_elementFunction · 0.85
EventClass · 0.85
update_activityFunction · 0.85
get_user_idFunction · 0.85
log_followed_poolFunction · 0.85

Tested by

no test coverage detected