tweepbot/twitools/__init__.py

48 lines
1.3 KiB
Python
Raw Normal View History

import dbtools, tweepy, setuptools
2017-02-08 13:10:56 +00:00
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):
2017-02-08 13:10:56 +00:00
''' 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):
2017-02-08 13:10:56 +00:00
for id in list(two.api.friends_ids(screen_name=twObject().whoami())):
yield int(id)
def getNameByID(uid, two):
2017-02-08 13:10:56 +00:00
return two.api.get_user(uid).screen_name
def getNamesByIDs(fids, two):
2017-02-08 13:10:56 +00:00
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}
def twoHelper(cid):
db = dbtools.dbHelper()
return twObject(db.ato(cid), db.ase(cid))