Created
January 17, 2019 11:33
-
-
Save cuducos/3d2f4c3e6a8b500e41b00e1c2f6c1cb6 to your computer and use it in GitHub Desktop.
twitter-followers.py
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
from os import getenv | |
from re import sub | |
from tweepy import API, Cursor, OAuthHandler | |
from tweepy.models import User | |
def followers(): | |
auth = OAuthHandler( | |
getenv("TWITTER_CONSUMER_KEY"), getenv("TWITTER_CONSUMER_SECRET") | |
) | |
auth.set_access_token( | |
getenv("TWITTER_ACCESS_TOKEN_KEY"), getenv("TWITTER_ACCESS_TOKEN_SECRET") | |
) | |
api = API(auth, wait_on_rate_limit=True) | |
for users in Cursor(api.followers).pages(): | |
yield from (User.parse(api, user._json) for user in users) | |
def filter_users(users): | |
yield from (user for user in users if len(sub(r"\D", "", user.screen_name)) >= 4) | |
if __name__ == "__main__": | |
for user in filter_users(followers()): | |
print(user.screen_name) |
Author
cuducos
commented
Jan 17, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment