#!/usr/bin/python3 # # followerdump.py # # Dumps the list of your Twitter followers to stdout in the format # # username displayname UID # # Copyright © 2017–2019 by martin f. krafft # Released under the Artistic Licence 2.0 # from authdata import * import twython import itertools import time import sys twitter = twython.Twython(app_key=consumer_key, app_secret=consumer_secret, oauth_token=access_token, oauth_token_secret=access_secret) def grouper(iterable, n, fillvalue=None): "Collect data into fixed-length chunks or blocks" args = [iter(iterable)] * n return itertools.zip_longest(fillvalue=fillvalue, *args) i=0 followers = twitter.cursor(twitter.get_followers_ids, count=5000, stringify_ids=True) #print('Obtained followers…', file=sys.stderr) for chunk in grouper(followers, 100): chunk = [c for c in chunk if c] #print(' fetching user data for chunk of {0:d} users…'.format(len(chunk)), # file=sys.stderr) n = 0 for follower in twitter.lookup_user(user_id=','.join(chunk)): #print(' [{0:02d}] @{1:s}'.format(n, follower['screen_name']), # file=sys.stderr) n += 1 print('\t'.join([follower[i] for i in ('screen_name','name','id_str')]))