Move follower functions to twitools
Create tables for storing followers and following in setup.py
This commit is contained in:
parent
6cca926188
commit
41f5fa288a
|
@ -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__":
|
||||
|
|
2
setup.py
2
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()
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue