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()
|
line = Line.objects.filter(clean_text_contains=params['topic']).random()
|
||||||
return line.to_dict()
|
return line.to_dict()
|
||||||
except Line.DoesNotExist:
|
except Line.DoesNotExist:
|
||||||
raise NotFound("Line not found")
|
raise BadRequest("Line not found")
|
||||||
|
|
||||||
@route_get('lines/rhyme', args={'word' : str})
|
@route_get('lines/rhyme', args={'word' : str})
|
||||||
def get_rhyme_line(params):
|
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()
|
rhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswidth=" "+params['word']).first()
|
||||||
return rhyme.to_dict()
|
return rhyme.to_dict()
|
||||||
except Rhyme.DoesNotExist:
|
except Rhyme.DoesNotExist:
|
||||||
raise NotFound("Rhyme not found")
|
raise BadRequest("Rhyme not found")
|
||||||
|
|
||||||
@route_get('couplets/random', args={})
|
@route_get('couplets/random', args={})
|
||||||
def get_random_couplet(params):
|
def get_random_couplet(params):
|
||||||
|
@ -29,9 +29,9 @@ def get_random_couplet(params):
|
||||||
line = Line.objects.random()
|
line = Line.objects.random()
|
||||||
for rl in line.rhyming_lines().sample(1):
|
for rl in line.rhyming_lines().sample(1):
|
||||||
rhyme = rl
|
rhyme = rl
|
||||||
return {'lines' : [line, rhyme]}
|
return {'lines' : [line.text, rhyme.text]}
|
||||||
except Rhyme.DoesNotExist:
|
except Line.DoesNotExist:
|
||||||
raise NotFound("Rhyme Not Found")
|
raise BadRequest("Rhyme Not Found")
|
||||||
|
|
||||||
@route_get('couplets/about', args={'topic' : str})
|
@route_get('couplets/about', args={'topic' : str})
|
||||||
def get_about_couplet(params):
|
def get_about_couplet(params):
|
||||||
|
@ -39,9 +39,9 @@ def get_about_couplet(params):
|
||||||
line = Line.objects.filter(clean_text__contains=params['topics']).random()
|
line = Line.objects.filter(clean_text__contains=params['topics']).random()
|
||||||
for rl in line.rhyming_lines().sample(1):
|
for rl in line.rhyming_lines().sample(1):
|
||||||
rhyme = rl
|
rhyme = rl
|
||||||
return {'lines' : [line.text, rhyme.text]}
|
return {'lines': [line.text, rhyme.text], 'topic': params['topic']}
|
||||||
except:
|
except Line.DoesNotExist:
|
||||||
pass
|
raise BadRequest("Couplet not found with given topic")
|
||||||
|
|
||||||
@route_get('couplets/rhyme', args={'word' : str})
|
@route_get('couplets/rhyme', args={'word' : str})
|
||||||
def get_rhyme_couplet(params):
|
def get_rhyme_couplet(params):
|
||||||
|
@ -50,7 +50,10 @@ def get_rhyme_couplet(params):
|
||||||
#line = Line.
|
#line = Line.
|
||||||
for rl in line.rhyming_lines().sample(1):
|
for rl in line.rhyming_lines().sample(1):
|
||||||
rhyme = rl
|
rhyme = rl
|
||||||
return {lines : [lines.text, rhyme.text]}
|
return {'lines': [rhyme.text, toRhyme.text], 'word': params['word']}
|
||||||
except:
|
except Rhyme.DoesNotExist:
|
||||||
pass
|
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