diff --git a/followertxt.py b/followertxt.py index 7059b67..4e8deaa 100755 --- a/followertxt.py +++ b/followertxt.py @@ -3,16 +3,6 @@ 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) @@ -23,7 +13,7 @@ def getOutFile(dirname="followers"): def writeOutFile(outfile=getOutFile()): with open(getOutFile(), 'a') as f: - for follower in getNamesByIDs(getFollowerIDs()): + for follower in twitools.getNamesByIDs(twitools.getFollowerIDs()): f.write(follower + "\n") if __name__ == "__main__": diff --git a/setup.py b/setup.py index bf7cd21..f02b276 100755 --- a/setup.py +++ b/setup.py @@ -51,6 +51,8 @@ else: if not db.isInitialized(): db.executeQuery("CREATE TABLE tweets(`tweet_id` INTEGER NOT NULL, `in_reply_to_status_id` TEXT, `in_reply_to_user_id` TEXT, `timestamp` TEXT, `source` TEXT, `text` TEXT, `retweeted_status_id` TEXT, `retweeted_status_user_id` TEXT, `retweeted_status_timestamp` TEXT, `expanded_urls` TEXT, PRIMARY KEY(tweet_id));") db.executeQuery("CREATE TABLE messages(`id` INTEGER NOT NULL, `text` TEXT, `sender_id` INTEGER, `recipient_id` INTEGER, `created_at` TEXT, PRIMARY KEY(id));") + db.executeQuery("CREATE TABLE followers(`id` INTEGER NOT NULL, `since` TEXT, `until` TEXT);") + db.executeQuery("CREATE TABLE following(`id` INTEGER NOT NULL, `since` TEXT, `until` TEXT);") db.commit() db.closeConnection() diff --git a/twitools/__init__.py b/twitools/__init__.py index 8de5355..730d7de 100644 --- a/twitools/__init__.py +++ b/twitools/__init__.py @@ -18,3 +18,12 @@ class twObject: def whoami(self): return self.auth.get_username() +def getFollowerIDs(two=twObject()): + ''' Returns 5,000 follower IDs at most ''' + return two.api.followers_ids(screen_name=twObject().whoami()) + +def getNamesByIDs(fids=getFollowerIDs(), two=twObject()): + for page in setuptools.paginate(fids, 100): + followers = two.api.lookup_users(user_ids=page) + for follower in followers: + yield follower.screen_name