def get_statements(self): """ Returns list of random statements from the API. """ from twitter import TwitterError statements = [] # Generate a random word random_word = self.random_word(self.random_seed_word, self.lang) self.logger.info( u'Requesting 50 random tweets containing the word {}'.format( random_word)) tweets = self.api.GetSearch(term=random_word, count=50, lang=self.lang) for tweet in tweets: statement = Statement(tweet.text) if tweet.in_reply_to_status_id: try: status = self.api.GetStatus(tweet.in_reply_to_status_id) statement.add_response(Response(status.text)) statements.append(statement) except TwitterError as error: self.logger.warning(str(error)) self.logger.info('Adding {} tweets with responses'.format( len(statements))) return statements
def get_statement(self): from chatter.chatterbot.conversation import Statement as StatementObject from chatter.chatterbot.conversation import Response as ResponseObject statement = StatementObject(self.text, tags=[tag.name for tag in self.tags], extra_data=self.extra_data) for response in self.in_response_to: statement.add_response( ResponseObject(text=response.text, occurrence=response.occurrence)) return statement
def deserialize_responses(self, response_list): """ Takes the list of response items and returns the list converted to Response objects. """ Statement = self.get_model('statement') Response = self.get_model('response') proxy_statement = Statement('') for response in response_list: text = response['text'] del response['text'] proxy_statement.add_response(Response(text, **response)) return proxy_statement.in_response_to