app.py

app.py

# app.py

from flask import Flask, render_template, redirect, url_for, jsonify
import poembot
from peewee import *
import datetime

app = Flask(__name__)
db = SqliteDatabase('poems.db')

@app.route('/')
def hello():
    return "Hello world!"

@app.route('/poem')
def poem():
    poem = poembot.generate_poem()
    timestamp = datetime.datetime.now()

    new_poem = Poem(body=poem, created_at=timestamp)
    new_poem.save()

    return render_template('poem.html', poem=poem)

@app.route('/poems')
def poems():
    poems = Poem.select().order_by(Poem.id.desc())

    return render_template('poems.html', poems=poems)

class Poem(Model):
    body = CharField()
    created_at = DateField()

    class Meta:
        database = db

if __name__ == '__main__':
    app.run(debug=True)