Add followertxt to twitools

Modify followertxt such as to use credentials from config
Move followertxt's paginate() function to tools
This commit is contained in:
Klaus-Uwe Mitterer 2015-05-17 21:33:25 +02:00
parent 79ba9cc96d
commit 0c16692f1e
2 changed files with 29 additions and 1 deletions

19
followertxt.py Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import config, tools
import tweepy
outfile = "followers.txt"
auth = tweepy.OAuthHandler(config.cke, config.cse)
auth.set_access_token(config.ato, config.ase)
api = tweepy.API(auth)
follower_ids = api.followers_ids()
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")

View file

@ -1,6 +1,6 @@
import config
import csv, datetime, os, sqlite3, sys, tweepy
import csv, datetime, itertools, os, sqlite3, sys, tweepy
class dbObject:
@ -79,6 +79,15 @@ def getDate(date):
raise ValueError("Dates must be in YYYY-MM-DD format.")
def paginate(iterable, page_size):
while True:
i1, i2 = itertools.tee(iterable)
iterable, page = (itertools.islice(i1, page_size, None), list(itertools.islice(i2, page_size)))
if len(page) == 0:
break
yield page
def parseArgs(argv):
args = []
path = None