From 450bcf2040c8ac83c0e661242c9af3b6a1cd08c3 Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Thu, 14 Feb 2019 01:04:26 +0100 Subject: [PATCH] Add /quote route --- app/app.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/app.py b/app/app.py index 4b0447c..31311d5 100644 --- a/app/app.py +++ b/app/app.py @@ -5,6 +5,7 @@ from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate import requests import config +import random import re import pdb @@ -148,6 +149,13 @@ def add_quote(): db.session.commit() 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']) def list_quotes(): return render_template('quotes.html', quotes = reversed(models.Quote.query.all()))