generated from mwc/lab_server
Answers to checkpoint 3 lab riddles server
This commit is contained in:
parent
3a919ca0ec
commit
298a1981cf
|
@ -6,3 +6,44 @@ from random import choice, sample
|
|||
@route_get('lines/random', args={})
|
||||
def get_random_line(params):
|
||||
return {'line': Line.objects.random().text}
|
||||
|
||||
@route_get('lines/about', args={'topic' : str})
|
||||
def get_topic(params):
|
||||
topic = params['topic']
|
||||
return {'line': Line.objects.filter(clean_text__contains=topic).random().text}
|
||||
|
||||
@route_get('lines/rhyme', args={'word' : str})
|
||||
def get_rhyme(params):
|
||||
rhyme = params['word']
|
||||
return {'line': Rhyme.get_rhyme_for_word(rhyme).lines.exclude(clean_text__endswith=rhyme).random().text}
|
||||
|
||||
@route_get('couplets/random', args={})
|
||||
def get_couplet(params):
|
||||
line = Line.objects.random()
|
||||
rl = line.rhyming_lines().random()
|
||||
return {"lines": [line.text, rl.text]}
|
||||
|
||||
@route_get('couplets/about', args={'topic' : str})
|
||||
def get_couplet_topic(params):
|
||||
topic = params['topic']
|
||||
line = Line.objects.filter(clean_text__contains=topic).random()
|
||||
rl = line.rhyming_lines()
|
||||
if rl.count() == 0:
|
||||
raise NotFound("Couplet not found")
|
||||
else:
|
||||
rl = rl.random()
|
||||
return {"lines": [line.text, rl.text]}
|
||||
|
||||
@route_get('couplets/rhyme', args={'word' : str})
|
||||
def get_couplet_rhyme(params):
|
||||
rhyme = params['word']
|
||||
line_objects = Rhyme.get_rhyme_for_word(rhyme).lines.exclude(clean_text__endswith=rhyme).sample(2)
|
||||
lines = [line_object.text for line_object in line_objects]
|
||||
return {"lines": lines}
|
||||
|
||||
@route_get('triplets/rhyme', args={'word' : str})
|
||||
def get_triplet_rhyme(params):
|
||||
rhyme = params['word']
|
||||
line_objects = Rhyme.get_rhyme_for_word(rhyme).lines.exclude(clean_text__endswith=rhyme).sample(3)
|
||||
lines = [line_object.text for line_object in line_objects]
|
||||
return {"lines": lines}
|
Loading…
Reference in New Issue