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
import config, tools
import tweepy
import os, time, tweepy
outfile = "followers.txt"
auth = tweepy.OAuthHandler(config.cke, config.cse)
auth.set_access_token(config.ato, config.ase)
api = tweepy.API(auth)
def getFollowerIDs(two=tools.twObject()):
''' Returns 5,000 follower IDs at most '''
return two.api.followers_ids(screen_name=config.user)
follower_ids = api.followers_ids(screen_name=config.name)
def getNamesByIDs(fids=getFollowerIDs(), two=tools.twObject()):
for page in tools.paginate(fids, 100):
followers = two.api.lookup_users(user_ids=page)
for follower in followers:
yield follower.screen_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:
f.write(follower.screen_name + "\n")
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()