diff --git a/poem_server/app/views.py b/poem_server/app/views.py index 21bc171..a2d93a4 100644 --- a/poem_server/app/views.py +++ b/poem_server/app/views.py @@ -44,4 +44,10 @@ def get_random_couplet_that_rhymes_with(params): return {'lines': [first_line.text,second_line.text]} except: raise BadRequest(f'Error 400: Sorry, there are not at least two lines that rhyme with {params['topic']}.') - + +@route_get('word/rhyme',args={'rhyme': str}) +def get_random_word_that_rhymes_with(params): + try: + return {'word': Rhyme.get_rhyme_for_word(params['rhyme']).lines.exclude(clean_text__endswith=params['rhyme']).random().last_word()} + except: + raise BadRequest(f'Error 400: Sorry, there are no words that rhyme with {params['rhyme']}.') \ No newline at end of file