app.py

app.py

# app.py

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

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

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

@app.route('/talk/new')
def new_talk():
    title = talk_mashup_bot.generateTitle()
    return render_template('new_talk.html', title=title)

@app.route('/talk', methods=['POST', 'GET'])
def talk():
    if request.method == 'GET':
        return redirect(url_for('new_talk'))

    talk_title = request.form['form-title']
    talk_description = request.form['form-description']
    talk_timestamp = datetime.datetime.now()

    new_talk = Talk(title=talk_title, description=talk_description, created_at=talk_timestamp)
    new_talk.save()

    return render_template('talk.html', title=talk_title, description=talk_description, timestamp=talk_timestamp)

@app.route('/talks')
def talks():
    all_talks = Talk.select().order_by(Talk.id.desc())

    return render_template('talks.html', talks=all_talks)


class Talk(Model):
    title = CharField()
    description = CharField()
    created_at = DateField()

    class Meta:
        database = db

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