Make followertxt more pretty

This commit is contained in:
Klaus-Uwe Mitterer 2015-05-18 13:05:14 +02:00
parent 99d7267688
commit f1ceb138bf

View file

@ -1,19 +1,30 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import config, tools import config, tools
import tweepy import os, time, tweepy
outfile = "followers.txt" def getFollowerIDs(two=tools.twObject()):
''' Returns 5,000 follower IDs at most '''
return two.api.followers_ids(screen_name=config.user)
auth = tweepy.OAuthHandler(config.cke, config.cse) def getNamesByIDs(fids=getFollowerIDs(), two=tools.twObject()):
auth.set_access_token(config.ato, config.ase) for page in tools.paginate(fids, 100):
api = tweepy.API(auth) followers = two.api.lookup_users(user_ids=page)
follower_ids = api.followers_ids(screen_name=config.name)
with open(outfile, 'a') as f:
for page in tools.paginate(follower_ids, 100):
followers = api.lookup_users(user_ids=page)
for follower in followers: for follower in followers:
f.write(follower.screen_name + "\n") 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()