twitools/followertxt.py

30 lines
873 B
Python
Executable file

#!/usr/bin/env python3
import twitools, setuptools
import os, time, tweepy
def getFollowerIDs(two=twitools.twObject()):
''' Returns 5,000 follower IDs at most '''
return two.api.followers_ids(screen_name=twitools.twObject().whoami())
def getNamesByIDs(fids=getFollowerIDs(), two=twitools.twObject()):
for page in setuptools.paginate(fids, 100):
followers = two.api.lookup_users(user_ids=page)
for follower in followers:
yield follower.screen_name
def getOutDir(dirname="followers"):
if not os.path.isdir(dirname):
os.mkdir(dirname)
def getOutFile(dirname="followers"):
getOutDir(dirname)
return os.path.join(dirname, str(int(time.time())) + ".txt")
def writeOutFile(outfile=getOutFile()):
with open(getOutFile(), 'a') as f:
for follower in getNamesByIDs(getFollowerIDs()):
f.write(follower + "\n")
if __name__ == "__main__":
writeOutFile()