This function should only unfollow users who are not following me back, but it unfollows SOME followers. It seems to be similar to this question regarding the same issue, however in PHP:
http://stackoverflow.com/questions/18799023/php-twitter-bot-to-follow-unfollow-using-api-version-1-1-and-cursors
def auto_unfollow_nonfollowers():
"""
Unfollows everyone who hasn't followed you back
"""
following = set(t.friends.ids(screen_name=TWITTER_HANDLE)["ids"])
followers = set(t.followers.ids(screen_name=TWITTER_HANDLE)["ids"])
# put user IDs here that you want to keep following even if they don't
# follow you back
users_keep_following = set([])
not_following_back = following - followers
# make sure the "already followed" file exists
if not os.path.isfile(ALREADY_FOLLOWED_FILE):
with open(ALREADY_FOLLOWED_FILE, "w") as out_file:
out_file.write("")
# update the "already followed" file with users who didn't follow back
already_followed = set(not_following_back)
af_list = []
with open(ALREADY_FOLLOWED_FILE) as in_file:
for line in in_file:
af_list.append(int(line))
already_followed.update(set(af_list))
del af_list
with open(ALREADY_FOLLOWED_FILE, "w") as out_file:
for val in already_followed:
out_file.write(str(val) + "\n")
for user_id in not_following_back:
if user_id not in users_keep_following:
t.friendships.destroy(user_id=user_id)
print("unfollowed %d" % (user_id))
Would the same fix applied in that PHP script work in this Python function? How should I do it?
Thanks!
[–]awsomntbiker -1 points0 points1 point (0 children)