Copy over twitools from twitools
This commit is contained in:
parent
33809c505d
commit
d8ea9a93a8
1 changed files with 44 additions and 0 deletions
44
twitools/__init__.py
Normal file
44
twitools/__init__.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
import tweepy, setuptools
|
||||
|
||||
class twObject:
|
||||
|
||||
def __init__(self, ato, ase, cke = setuptools.cke(), cse = setuptools.cse()):
|
||||
self.auth = tweepy.OAuthHandler(cke, cse)
|
||||
self.auth.set_access_token(ato, ase)
|
||||
self.api = tweepy.API(self.auth)
|
||||
|
||||
def retweet(self, id):
|
||||
self.api.retweet(id)
|
||||
|
||||
def delete(self, id):
|
||||
self.api.destroy_status(id)
|
||||
|
||||
def search(self, query, savepoint = 0):
|
||||
tweets = list(tweepy.Cursor(self.api.search, q=query, since_id=savepoint).items())
|
||||
tweets.reverse()
|
||||
return tweets
|
||||
|
||||
def whoami(self):
|
||||
return self.auth.get_username()
|
||||
|
||||
def tweet(self, text, reply = 0):
|
||||
return self.api.update_status(text, reply)
|
||||
|
||||
def getFollowerIDs(two=twObject()):
|
||||
''' Returns 5,000 follower IDs at most '''
|
||||
for id in list(two.api.followers_ids(screen_name=twObject().whoami())):
|
||||
yield int(id)
|
||||
|
||||
def getFollowingIDs(two=twObject()):
|
||||
for id in list(two.api.friends_ids(screen_name=twObject().whoami())):
|
||||
yield int(id)
|
||||
|
||||
def getNameByID(uid, two=twObject()):
|
||||
return two.api.get_user(uid).screen_name
|
||||
|
||||
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 {"id": follower.id, "name": follower.screen_name}
|
||||
|
Loading…
Reference in a new issue