Exemple #1
0
    def __public_response(self, messages):
        message = None
        
        for m in messages:
            pretty_message = "%s [%s %s] %s" % (m.id, m.created_at, m.user.screen_name, m.text)
            logging.info("found public message: %s" % pretty_message)
            if not self.__analyzer.should_respond(m):
                logging.info("not responding")
                continue
                
            response = TwitterResponseAccessor.get_by_message_id(str(m.id))
            if not response:
                message = m
                break
            else:
                logging.debug("found response to public message %s" % m.id)
        
        sent_message = None
        if message:
            # TODO: search for username also
            username = message.user.screen_name
            parsed_tweet = parse_tweet(message.text)
            plain_tweet = parsed_tweet.plain_text
            speaker = self.__select_speaker()
            sources, mix = Mixer(speaker).mix_response(plain_tweet, min_results=1, max_length=130-len(username))
            response_text = "@%s %s" % (username, mix)
            logging.info("responding to public message %s: %s" % (message.id, response_text))
            
            sent_message = self.__twitter.PostUpdate(response_text, message.id)
            TwitterResponseAccessor.create(str(message.id), response_id=str(sent_message.id), user=username, tweet_type=TwitterResponse.MENTION) 
            self.__reporter.posted(response_text)

        return sent_message
Exemple #2
0
    def test_multiple_users(self):
        tweet = "@livelock why is blood spattered all over @mhawthorne's car?"
        plain_text = "why is blood spattered all over 's car?"
        users = ["livelock", "mhawthorne"]

        result = parse_tweet(tweet)
        self.assertEquals(plain_text, result.plain_text)
        self.assertEquals(plain_text.split(), result.plain_words)
        self.assertEquals(result.usernames, users)
Exemple #3
0
    def test_single_user(self):
        tweet = "@livelock why is blood spattered all over the car?"
        plain_text = "why is blood spattered all over the car?"
        users = ["livelock"]

        result = parse_tweet(tweet)
        self.assertEquals(plain_text, result.plain_text)
        self.assertEquals(plain_text.split(), result.plain_words)
        self.assertEquals(result.usernames, users)
Exemple #4
0
 def test_multiple_users(self):
     tweet = "@livelock why is blood spattered all over @mhawthorne's car?"
     plain_text = "why is blood spattered all over 's car?"
     users = ["livelock", "mhawthorne"]
     
     result = parse_tweet(tweet)
     self.assertEquals(plain_text, result.plain_text)
     self.assertEquals(plain_text.split(), result.plain_words)
     self.assertEquals(result.usernames, users)
Exemple #5
0
 def test_single_user(self):
     tweet = "@livelock why is blood spattered all over the car?"
     plain_text = "why is blood spattered all over the car?"
     users = ["livelock"]
     
     result = parse_tweet(tweet)
     self.assertEquals(plain_text, result.plain_text)
     self.assertEquals(plain_text.split(), result.plain_words)
     self.assertEquals(result.usernames, users)
Exemple #6
0
    def __public_response(self, messages):
        message = None

        for m in messages:
            pretty_message = "%s [%s %s] %s" % (m.id, m.created_at,
                                                m.user.screen_name, m.text)
            logging.info("found public message: %s" % pretty_message)
            if not self.__analyzer.should_respond(m):
                logging.info("not responding")
                continue

            response = TwitterResponseAccessor.get_by_message_id(str(m.id))
            if not response:
                message = m
                break
            else:
                logging.debug("found response to public message %s" % m.id)

        sent_message = None
        if message:
            # TODO: search for username also
            username = message.user.screen_name
            parsed_tweet = parse_tweet(message.text)
            plain_tweet = parsed_tweet.plain_text
            speaker = self.__select_speaker()
            sources, mix = Mixer(speaker).mix_response(plain_tweet,
                                                       min_results=1,
                                                       max_length=130 -
                                                       len(username))
            response_text = "@%s %s" % (username, mix)
            logging.info("responding to public message %s: %s" %
                         (message.id, response_text))

            sent_message = self.__twitter.PostUpdate(response_text, message.id)
            TwitterResponseAccessor.create(str(message.id),
                                           response_id=str(sent_message.id),
                                           user=username,
                                           tweet_type=TwitterResponse.MENTION)
            self.__reporter.posted(response_text)

        return sent_message
Exemple #7
0
 def test_no_users(self):
     tweet = "why is blood spattered all over the car?"
     result = parse_tweet(tweet)
     self.assertEquals(tweet, result.plain_text)
     self.assertEquals(tweet.split(), result.plain_words)
Exemple #8
0
 def test_no_users(self):
     tweet = "why is blood spattered all over the car?"
     result = parse_tweet(tweet)
     self.assertEquals(tweet, result.plain_text)
     self.assertEquals(tweet.split(), result.plain_words)