def gen_markov(): # pragma: no cover
"""Compile all the tweets and create a Markov chain."""
host_url = os.environ.get('REDIS_URL')
access_dict = {'sqlalchemy.url': os.environ.get('DATABASE_URL')}
engine = get_engine(access_dict)
SessionFactory = sessionmaker(bind=engine)
session = SessionFactory()
tweets = session.query(Tweet).all()
big_corpus = ''
for tweet in tweets:
big_corpus += tweet.tweet + '\n'
markov_chain = markovify.NewlineText(big_corpus, state_size=3)
to_redis = pickle.dumps(markov_chain)
redis.from_url(host_url).set('markov_tweets', to_redis)
评论列表
文章目录