Finished Poem Server

This commit is contained in:
louiscooper136 2024-05-14 19:55:42 -04:00
parent 2ef980daa5
commit 3b7994a4a9
1 changed files with 14 additions and 11 deletions

View File

@ -13,7 +13,7 @@ def get_about_line(params):
line = Line.objects.filter(clean_text_contains=params['topic']).random()
return line.to_dict()
except Line.DoesNotExist:
raise NotFound("Line not found")
raise BadRequest("Line not found")
@route_get('lines/rhyme', args={'word' : str})
def get_rhyme_line(params):
@ -21,7 +21,7 @@ def get_rhyme_line(params):
rhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswidth=" "+params['word']).first()
return rhyme.to_dict()
except Rhyme.DoesNotExist:
raise NotFound("Rhyme not found")
raise BadRequest("Rhyme not found")
@route_get('couplets/random', args={})
def get_random_couplet(params):
@ -29,9 +29,9 @@ def get_random_couplet(params):
line = Line.objects.random()
for rl in line.rhyming_lines().sample(1):
rhyme = rl
return {'lines' : [line, rhyme]}
except Rhyme.DoesNotExist:
raise NotFound("Rhyme Not Found")
return {'lines' : [line.text, rhyme.text]}
except Line.DoesNotExist:
raise BadRequest("Rhyme Not Found")
@route_get('couplets/about', args={'topic' : str})
def get_about_couplet(params):
@ -39,9 +39,9 @@ def get_about_couplet(params):
line = Line.objects.filter(clean_text__contains=params['topics']).random()
for rl in line.rhyming_lines().sample(1):
rhyme = rl
return {'lines' : [line.text, rhyme.text]}
except:
pass
return {'lines': [line.text, rhyme.text], 'topic': params['topic']}
except Line.DoesNotExist:
raise BadRequest("Couplet not found with given topic")
@route_get('couplets/rhyme', args={'word' : str})
def get_rhyme_couplet(params):
@ -50,7 +50,10 @@ def get_rhyme_couplet(params):
#line = Line.
for rl in line.rhyming_lines().sample(1):
rhyme = rl
return {lines : [lines.text, rhyme.text]}
except:
pass
return {'lines': [rhyme.text, toRhyme.text], 'word': params['word']}
except Rhyme.DoesNotExist:
raise BadRequest("Did not fnid a couplet with a Rhyme")
except Exception as e:
if isinstance(e, BadRequest):
raise BadRequest(f"Couldnt figure out how to pronounce {params['word']}")