def post(self): form = self.form(request.form) if form.validate(): muse = Muse() form.populate_obj(muse) muse.save() return redirect(url_for('muse_api')) return redirect(url_for('muse_api'))
def ponder(): """ Fetch tweets from the Muses and memorize them; i.e. train classifier or Markov on them. """ logger.info('Pondering new twitter data...') # Each of these are just a list # of tweets as strings. pos = [] neg = [] # For the good muses... for muse in Muse.objects(negative=False): pos += _process_muse(muse) # For the evil muses... for muse in Muse.objects(negative=True): neg += _process_muse(muse) # Extract the tweet contents into lists. pos_txts = _get_tweet_texts(pos) neg_txts = _get_tweet_texts(neg) # Construct training matrix and labels. labels = [1 for i in range(len(pos_txts)) ] + [0 for i in range(len(neg_txts))] # See if there's anything to retweet. _consider_retweets(pos) # Combine the new tweets. new_tweets = pos_txts + neg_txts # Update the classifier and markov. logger.info('Collected %s new tweets, training...' % len(new_tweets)) CLS.train(new_tweets, labels) MKV.train(pos_txts)
def ponder(): """ Fetch tweets from the Muses and memorize them; i.e. train classifier or Markov on them. """ logger.info("Pondering new twitter data...") # Each of these are just a list # of tweets as strings. pos = [] neg = [] # For the good muses... for muse in Muse.objects(negative=False): pos += _process_muse(muse) # For the evil muses... for muse in Muse.objects(negative=True): neg += _process_muse(muse) # Extract the tweet contents into lists. pos_txts = _get_tweet_texts(pos) neg_txts = _get_tweet_texts(neg) # Construct training matrix and labels. labels = [1 for i in range(len(pos_txts))] + [0 for i in range(len(neg_txts))] # See if there's anything to retweet. _consider_retweets(pos) # Combine the new tweets. new_tweets = pos_txts + neg_txts # Update the classifier and markov. logger.info("Collected %s new tweets, training..." % len(new_tweets)) CLS.train(new_tweets, labels) MKV.train(pos_txts)