Skip to content

Instantly share code, notes, and snippets.

@sumeetpareek
Created November 10, 2022 04:00
Show Gist options
  • Save sumeetpareek/3b056183f99d1ac046fbef17e88f2356 to your computer and use it in GitHub Desktop.
Save sumeetpareek/3b056183f99d1ac046fbef17e88f2356 to your computer and use it in GitHub Desktop.
Script that prints a list of all twitter accounts that I follow
# get the list of accounts i follow on twitter
# and print out their URLs, so i can visit
# some of them randomly during coding breaks
# and unfollow accounts that don't add value
import tweepy
# twitter credentials
# SEARCH: how to get twitter credentials
# SEE: https://www.jcchouinard.com/twitter-api-credentials/
consumer_key = "TODO"
consumer_secret = "TODO"
access_token = "TODO"
access_token_secret = "TODO"
# authorize the api
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# get the list of accounts i follow on twitter
# NOTE: this only returns id's (not names, or urls)
friends = api.get_friend_ids()
# break the list into chunks of 50 because
# the twitter api only allows 100 ids per request
chunks = [friends[x:x+50] for x in range(0, len(friends), 50)]
# for each chunk, get the user objects
# and print out their screen_names
for chunk in chunks:
users = api.lookup_users(user_id=chunk)
for user in users:
print (user.screen_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment