Add /quote route

This commit is contained in:
Rien Maertens 2019-02-14 01:04:26 +01:00
parent 7ab27fd9ef
commit 450bcf2040
No known key found for this signature in database
GPG key ID: 10C6D8C91DE58E4A

View file

@ -5,6 +5,7 @@ from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate from flask_migrate import Migrate
import requests import requests
import config import config
import random
import re import re
import pdb import pdb
@ -148,6 +149,13 @@ def add_quote():
db.session.commit() db.session.commit()
return mattermost_response("{} added the quote \"{}\"".format(user, quote_text)) return mattermost_response("{} added the quote \"{}\"".format(user, quote_text))
@app.route('/quote', methods=['GET'])
def random_quote():
text_contains = request.values['text']
matches = models.Quote.query.filter(models.Quote.quote.contains(text_contains))
return mattermost_response(random.choice(matches))
@app.route('/', methods=['GET']) @app.route('/', methods=['GET'])
def list_quotes(): def list_quotes():
return render_template('quotes.html', quotes = reversed(models.Quote.query.all())) return render_template('quotes.html', quotes = reversed(models.Quote.query.all()))