Add /quote route
This commit is contained in:
parent
7ab27fd9ef
commit
450bcf2040
1 changed files with 8 additions and 0 deletions
|
@ -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()))
|
||||||
|
|
Loading…
Reference in a new issue