generated from mwc/lab_server
21 lines
627 B
Python
21 lines
627 B
Python
from banjo.urls import route_get, route_post
|
|
from banjo.http import BadRequest, NotFound
|
|
from app.models import Line, Poem, Rhyme
|
|
from random import choice, sample
|
|
|
|
@route_get('lines/random', args={})
|
|
def get_random_line(params):
|
|
return {'line': Line.objects.random().text}
|
|
|
|
@route_get('lines/about', args={'topic': str})
|
|
def get_about_line(params):
|
|
word = params['topic']
|
|
if not Line.objects.filter(clean_text__contains=word):
|
|
raise NotFound("no line with that topic")
|
|
line = Line.objects.filter(clean_text__contains=word).random()
|
|
retval = {'line': line.text, 'topic' : word}
|
|
return retval
|
|
|
|
|
|
|