Ejemplo n.º 1
0
class TwitterBot(object):
    """docstring for TwitterBot"""
    def __init__(self, account_name):
        super(TwitterBot, self).__init__()
        self.__app = secrets['twitter']['app']
        self.__account = secrets['twitter']['accounts'][account_name]
        self._api_client = twitter.Api(consumer_key = self.__app['consumer_key'],
                                       consumer_secret = self.__app['consumer_secret'],
                                       access_token_key = self.__account['token_key'],
                                       access_token_secret = self.__account['token_secret'])
        self.user = self._api_client.GetUser(user_id=self.__account['user_id'])
        self.db = TweetDatastore(account_name)
        self.__backfill_db()

    def __backfill_db(self):
        try:
            tweets = self._api_client.GetUserTimeline(user_id=self.__account['user_id'], count = 200)
            self.db.store(tweets)
        except Exception, e:
            pass