コード例 #1
0
    with open(clean_data_file, 'r') as f:
        for line in f:
            for word in line.split():
                yield word


if __name__ == '__main__':
    logging.info("Initializing bot_data file.")
    with open(bot_data_file, 'w') as file:
        json.dump({"last_id_seen": None, "last_reply_id_seen": None}, file)

    markov = Markov()
    twitterbot = TwitterBot()

    logging.info("Connecting to the database.")
    markov._connect_db()
    markov.cur.execute(
        """
        SELECT EXISTS(SELECT 1 FROM information_schema.tables \
        WHERE table_catalog=%(db_name)s \
        AND table_schema='public' \
        AND table_name='transition');
        """, {'db_name': config.DATABASE_NAME})
    table_exists = markov.cur.fetchone()[0]

    if not table_exists:
        logging.info("Transition table does not exist.  Creating it now...")
        markov.cur.execute("""
            CREATE TABLE transition ( \
            first_word VARCHAR, \
            second_word VARCHAR, \