generated from mwc/lab_server
Did some of poem_server, haven't handled exception
Can get all but the couplet with both lines rhyming with word working, haven't figured out how to get the exceptions handled yet.
This commit is contained in:
parent
d88926dbdd
commit
50252d9769
|
@ -6,3 +6,51 @@ from random import choice, sample
|
||||||
@route_get('lines/random', args={})
|
@route_get('lines/random', args={})
|
||||||
def get_random_line(params):
|
def get_random_line(params):
|
||||||
return {'line': Line.objects.random().text}
|
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:
|
||||||
|
raise NotFound("Line not found")
|
||||||
|
|
||||||
|
@route_get('lines/rhyme', args={'word': str})
|
||||||
|
def get_rhyme_line(params):
|
||||||
|
try:
|
||||||
|
rhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=" "+params['word']).first()
|
||||||
|
return rhyme.to_dict()
|
||||||
|
except Rhyme.DoesNotExist:
|
||||||
|
raise NotFound("Rhyme not found")
|
||||||
|
|
||||||
|
@route_get('couplets/random', args={})
|
||||||
|
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 Line.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={'word': str})
|
||||||
|
def get_rhyme_couplet(params):
|
||||||
|
try:
|
||||||
|
toRhyme = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=" " + params['word']).first()
|
||||||
|
line = Line.
|
||||||
|
for rl in line.rhyming_lines().sample(1):
|
||||||
|
rhyme = rl
|
||||||
|
return {'lines': [line.text, rhyme.text]}
|
||||||
|
except:
|
||||||
|
pass
|
Loading…
Reference in New Issue