From 6a6cc40c535ffc55959ec9d22263d732d75967c2 Mon Sep 17 00:00:00 2001 From: Justin Toombs Date: Thu, 2 May 2024 21:54:43 -0400 Subject: [PATCH] Worked with a group to develop final component of lab, still working on finishing DoesNotExist and couplet component. --- poem_server/app/views.py | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/poem_server/app/views.py b/poem_server/app/views.py index 9a20b83..6300fba 100644 --- a/poem_server/app/views.py +++ b/poem_server/app/views.py @@ -6,3 +6,50 @@ 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): + try: + line = Line.objects.filter(clean_text__contains=params['topic']).random() + return line.to_dict() + except Line.DoesNotExist: + raise NotFound("Line not found") + +@route_get('lines/rhyme', args={'word': str}) +def get_line_rhyme(params): + try: + rhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=" "+params['word']).first() + return rhyme.to_dict() + except: + raise NotFound("Rhyme not found") + +@route_get('couplets/random', args={'topic': str}) +def get_random_couplet(params): + try: + line = Line.objects.random() + for rl in line.rhyming_lines().sample(1): + rhyme = rl + #print(rhyme.text) + return{'lines': [line.text, rhyme.text]} + except Rhyme.DoesNotExist: + raise NotFound("Rhyme not found") + +@route_get('couplets/about', args={'topic': str}) +def get_about_couplet(params): + try: + line = Line.objects.filter(clean_text__contains=params['topic']).random() + for rl in line.rhyming_lines().sample(1): + rhyme = rl + return {'lines': [line.text, rhyme.text]} + except: + pass + +@route_get('couplets/rhyme', args={'topic': str}) +def get_rhyme_couplet(params): + try: + toRhyme = Rhyme.get_rhyme_for_word + for rl in line.rhyming_lines().sample(1): + rhyme = rl + return {'lines': [line.text, rhyme.text]} + except: + pass