generated from mwc/lab_server
Completed lab with help of peers. There are still
issues with the BadRequest but it is not necessary for basic functionality.
This commit is contained in:
parent
6a6cc40c53
commit
c4617e0f65
|
@ -11,19 +11,20 @@ def get_random_line(params):
|
||||||
def get_about_line(params):
|
def get_about_line(params):
|
||||||
try:
|
try:
|
||||||
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': line.text, 'topic': params['topic']}
|
||||||
except Line.DoesNotExist:
|
except Line.DoesNotExist:
|
||||||
raise NotFound("Line not found")
|
raise BadRequest("Line not found with that topic")
|
||||||
|
|
||||||
@route_get('lines/rhyme', args={'word': str})
|
@route_get('lines/rhyme', args={'word': str})
|
||||||
def get_line_rhyme(params):
|
def get_rhyme_line(params):
|
||||||
try:
|
try:
|
||||||
rhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=" "+params['word']).first()
|
rhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=" "+params['word']).first()
|
||||||
|
return {'line': rhyme.text, 'word': params['word']}
|
||||||
return rhyme.to_dict()
|
return rhyme.to_dict()
|
||||||
except:
|
except Rhyme.DoesNotExist:
|
||||||
raise NotFound("Rhyme not found")
|
raise BadRequest("Rhyme not found")
|
||||||
|
|
||||||
@route_get('couplets/random', args={'topic': str})
|
@route_get('couplets/random', args={})
|
||||||
def get_random_couplet(params):
|
def get_random_couplet(params):
|
||||||
try:
|
try:
|
||||||
line = Line.objects.random()
|
line = Line.objects.random()
|
||||||
|
@ -31,8 +32,8 @@ def get_random_couplet(params):
|
||||||
rhyme = rl
|
rhyme = rl
|
||||||
#print(rhyme.text)
|
#print(rhyme.text)
|
||||||
return {'lines': [line.text, rhyme.text]}
|
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):
|
||||||
|
@ -40,16 +41,17 @@ def get_about_couplet(params):
|
||||||
line = Line.objects.filter(clean_text__contains=params['topic']).random()
|
line = Line.objects.filter(clean_text__contains=params['topic']).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={'topic': str})
|
@route_get('couplets/rhyme', args={'word': str})
|
||||||
def get_rhyme_couplet(params):
|
def get_rhyme_couplet(params):
|
||||||
try:
|
try:
|
||||||
toRhyme = Rhyme.get_rhyme_for_word
|
toRhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=" " + params['word']).first()
|
||||||
for rl in line.rhyming_lines().sample(1):
|
#line = Line.
|
||||||
|
for rl in toRhyme.rhyming_lines().sample(1):
|
||||||
rhyme = rl
|
rhyme = rl
|
||||||
return {'lines': [line.text, rhyme.text]}
|
return {'lines': [rhyme.text, toRhyme.text], 'word': params['word']}
|
||||||
except:
|
except Rhyme.DoesNotExist:
|
||||||
pass
|
raise BadRequest("Did not find a couplet that rhymes with given word")
|
||||||
|
|
Loading…
Reference in New Issue