generated from mwc/lab_server
Finished Poem Server
This commit is contained in:
parent
2ef980daa5
commit
3b7994a4a9
|
@ -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']}")
|
||||
|
||||
|
|
Loading…
Reference in New Issue