def is_macedonian_user(api, iduser, all_users, max_followers=70000, threshold_followers=0.01, threshold_friends=0.01): user = api.get_user(id=iduser) # We already have the users with most followers, so if there is someone with more followers, then he is not macedonian if user.followers_count > max_followers or user.friends_count > max_followers: return False, set(), set() friends = API.get_friends_ids(api, iduser) followers = API.get_followers_ids(api, iduser) macedonian_friends = len(friends & all_users) macedonian_followers = len(followers & all_users) # If greater part of friends and followers are macedonians, then this user is probably also macedonian print user.screen_name return 1.0 * macedonian_friends / (1 + len(friends)) > threshold_friends and \ 1.0 * macedonian_followers / (1 + len(followers)) > threshold_followers, \ [(iduser, f) for f in friends], [(iduser, f) for f in followers]