MCPcopy Index your code
hub / github.com/InstaPy/InstaPy / get_mutual_following

Function get_mutual_following

instapy/relationship_tools.py:873–944  ·  view source on GitHub ↗

Find Mutual Following of a given user

(
    browser,
    self_username,
    username,
    relationship_data,
    live_match,
    store_locally,
    logger,
    logfolder,
)

Source from the content-addressed store, hash-verified

871
872
873def get_mutual_following(
874 browser,
875 self_username,
876 username,
877 relationship_data,
878 live_match,
879 store_locally,
880 logger,
881 logfolder,
882):
883 """Find Mutual Following of a given user"""
884
885 if username is None or type(username) != str:
886 logger.info(
887 "Please enter a username to pick Mutual Following ~leaving out "
888 "of an invalid value"
889 )
890 return []
891
892 # get `Followers` data
893 all_followers = get_followers(
894 browser,
895 self_username,
896 username,
897 "full",
898 relationship_data,
899 live_match,
900 store_locally,
901 logger,
902 logfolder,
903 )
904
905 # if all_followers is False we have targeted a private account that we don't follow
906 if not all_followers:
907 return False
908
909 # get `Following` data
910 all_following = get_following(
911 browser,
912 self_username,
913 username,
914 "full",
915 relationship_data,
916 live_match,
917 store_locally,
918 logger,
919 logfolder,
920 )
921
922 # using this approach we can preserve the order of elements to be used
923 # with `FIFO`, `LIFO` or `RANDOM` styles
924 mutual_following = [user for user in all_following if user in all_followers]
925
926 # uniqify elements
927 mutual_following = sorted(set(mutual_following), key=mutual_following.index)
928
929 logger.info(
930 "There are {0} Mutual Following of {1} ~the users {1} is following "

Callers 1

pick_mutual_followingMethod · 0.85

Calls 3

get_followersFunction · 0.85
get_followingFunction · 0.85
store_mutual_followingFunction · 0.85

Tested by

no test coverage detected