generated from mwc/lab_server
22 lines
645 B
Python
22 lines
645 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):
|
|
'Get a random line of poetry'
|
|
return {'line': Line.objects.random().text}
|
|
|
|
@route_get('lines/about/<topic>', args={'topic': str})
|
|
def get_about_topic(params):
|
|
'Get a random line of poetry about a selected topic'
|
|
topic = params['topic']
|
|
if not topic:
|
|
raise BadRequest("Please enter a topic")
|
|
return {'line': Line.objects.filter(clean_text__contains=topic).random().text}
|
|
|
|
|
|
|
|
|