generated from mwc/lab_server
app/views.py
This commit is contained in:
@@ -18,8 +18,7 @@ def get_about_line(params):
|
|||||||
return {'line': Line.objects.filter(clean_text__contains=topic).random().text, 'topic':topic}
|
return {'line': Line.objects.filter(clean_text__contains=topic).random().text, 'topic':topic}
|
||||||
except Line.DoesNotExist:
|
except Line.DoesNotExist:
|
||||||
raise NotFound("Line not found")
|
raise NotFound("Line not found")
|
||||||
except Line.BadRequest:
|
|
||||||
raise BadRequest("Bad request")
|
|
||||||
|
|
||||||
@route_get('lines/rhyme', args={'word': str})
|
@route_get('lines/rhyme', args={'word': str})
|
||||||
def get_rhyme_line(params):
|
def get_rhyme_line(params):
|
||||||
@@ -29,8 +28,50 @@ def get_rhyme_line(params):
|
|||||||
= " " + word).random().text, 'word':word}
|
= " " + word).random().text, 'word':word}
|
||||||
except Rhyme.DoesNotExist:
|
except Rhyme.DoesNotExist:
|
||||||
raise NotFound("Rhyme not found")
|
raise NotFound("Rhyme not found")
|
||||||
except Rhyme.BadRequest:
|
|
||||||
raise BadRequest("Bad request")
|
|
||||||
|
|
||||||
|
|
||||||
|
@route_get('couplets/random', args={})
|
||||||
|
def get_random_couplets(params):
|
||||||
|
line = Line.objects.random().text
|
||||||
|
word=line.split()[-1]
|
||||||
|
try:
|
||||||
|
if {'First Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text} != {'Second Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text}:
|
||||||
|
return {'First Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text, 'Second Line':line}
|
||||||
|
else:
|
||||||
|
return()
|
||||||
|
except Rhyme.DoesNotExist:
|
||||||
|
raise NotFound("Rhyme not found")
|
||||||
|
|
||||||
|
@route_get('couplets/about', args={'topic': str})
|
||||||
|
def get_about_couplets(params):
|
||||||
|
topic=params['topic']
|
||||||
|
line=Line.objects.filter(clean_text__contains=topic).random().text
|
||||||
|
word=line.split()[-1]
|
||||||
|
try:
|
||||||
|
if {'First Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text} != {'Second Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text}:
|
||||||
|
return {'First Line': line, 'Second Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text}
|
||||||
|
else:
|
||||||
|
return()
|
||||||
|
except Rhyme.DoesNotExist:
|
||||||
|
raise NotFound("Rhyme not found")
|
||||||
|
|
||||||
|
@route_get('couplets/rhyme', args={'word': str})
|
||||||
|
def get_rhyme_couplets(params):
|
||||||
|
word=params['word']
|
||||||
|
try:
|
||||||
|
if {'First Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text} != {'Second Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text}:
|
||||||
|
return {'First Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text, 'Second Line': Rhyme.get_rhyme_for_word(word).lines.exclude(clean_text__endswith
|
||||||
|
= " " + word).random().text}
|
||||||
|
else:
|
||||||
|
return()
|
||||||
|
except Rhyme.DoesNotExist:
|
||||||
|
raise NotFound("Rhyme not found")
|
||||||
|
|||||||
Reference in New Issue
Block a user