Created
January 12, 2021 09:21
-
-
Save denibertovic/032fccc63511fac70755254e405d503d to your computer and use it in GitHub Desktop.
Creating twitter lists from followers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import twitter | |
import os | |
CONSUMER_KEY = os.environ['CONSUMER_KEY'] | |
CONSUMER_SECRET = os.environ['CONSUMER_SECRET'] | |
ACCESS_TOKEN = os.environ['ACCESS_TOKEN'] | |
ACCESS_TOKEN_SECRET = os.environ['ACCESS_TOKEN_SECRET'] | |
LIST_ID = os.environ['TWITTER_LIST_ID'] | |
# Create an Api instance. | |
api = twitter.Api(consumer_key=CONSUMER_KEY, | |
consumer_secret=CONSUMER_SECRET, | |
access_token_key=ACCESS_TOKEN, | |
access_token_secret=ACCESS_TOKEN_SECRET) | |
users = api.GetFriends() | |
print("Following count: " + str(len(users))) | |
# print([u.id_str for u in users]) | |
user_ids = [u.id_str for u in users] | |
print("User ID count: " + str(len(user_ids))) | |
lists = api.GetLists() | |
members = api.GetListMembers(list_id=LIST_ID) | |
member_ids = [m.id_str for m in members] | |
print("Member ID count: " + str(len(member_ids))) | |
diff_ids = set(user_ids) - set(member_ids) | |
print("Diff ID count: " + str(len(diff_ids))) | |
for x in diff_ids: | |
api.CreateListsMember(list_id=LIST_ID, user_id=x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment