import dbtools, 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): ''' 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): for id in list(two.api.friends_ids(screen_name=twObject().whoami())): yield int(id) def getNameByID(uid, two): return two.api.get_user(uid).screen_name def getNamesByIDs(fids, two): 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))