def makeStatus(self, tweets): chain = MarkovChain() for tweet in tweets: chain.train(tweet) if not chain.isEmpty(): status = chain.generateCharacters(140) api.update_status(status)
def on_data(self, data): chain = MarkovChain() d = json.loads(data) sn = d['user']['screen_name'] users = re.findall(screenNamePattern, d['text']) users = [user for user in users if user != self.screenName] #hashtags = re.findall(hashtagPattern, text) for user in users: tweets = self.fetchUserTweets(user) tweets = self.processTweets(tweets) for tweet in tweets: chain.train(tweet) if not chain.isEmpty(): reply = chain.generateCharacters(140 - (len(sn)+2)) reply = '@' + sn + ' ' + reply api.update_status(reply, in_reply_to_status_id=d['id'])