diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..36e1371 Binary files /dev/null and b/.DS_Store differ diff --git a/poem_server/.DS_Store b/poem_server/.DS_Store new file mode 100644 index 0000000..da07aa6 Binary files /dev/null and b/poem_server/.DS_Store differ diff --git a/poem_server/app/views.py b/poem_server/app/views.py index 9a20b83..d57c76f 100644 --- a/poem_server/app/views.py +++ b/poem_server/app/views.py @@ -6,3 +6,62 @@ 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_lines_about(params): + try: + return {'line': Line.objects.filter(clean_text__contains=params['topic']).random().text + ,"topic": params['topic'] } + + + except Line.DoesNotExist: + raise NotFound("No lines with that topic") + +@route_get('lines/rhyme', args={'word': str}) +def get_lines_that_rhyme(params): + try: + return{'line': Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=params['word']).random().text, + "word": params['word']} + + except Line.DoesNotExist: + raise NotFound("No lines rhyme with that") + + +@route_get('couplets/random', args={}) +def get_random_couplet(params): + try: + lineOne = Line.objects.random() + lineTwo = lineOne.rhyming_lines().random() + return {'lines': [lineOne.text, lineTwo.text]} + except Line.DoesNotExist: + raise NotFound("No line rhymed with the random first one") + +@route_get('couplets/about', args={'topic':str}) +def get_couplet_about(params): + try: + lineOne = Line.objects.filter(clean_text__contains=params['topic']).random() + lineTwo = lineOne.rhyming_lines().random() + return {'lines': [lineOne.text, lineTwo.text], "topic": params['topic']} + + except Line.DoesNotExist: + raise NotFound("No lines with that topic or No line rhymed with the random first one") + +@route_get('couplets/rhyme', args={'word': str}) +def get_couplet_rhymes_with(params): + try: + lineOne = Rhyme.get_rhyme_for_word(params['word']).lines.exclude(clean_text__endswith=params['word']).random() + lineTwo = lineOne.rhyming_lines().random() + return {'lines': [lineOne.text, lineTwo.text], "word": params['word']} + except Line.DoesNotExist: + raise NotFound("Zero or One lines rhymed with your word. Not enough for a couplet!") + +@route_get('couplets/start', args={'word': str}) +def couplets_start_with(params): + try: + lineOne = Line.objects.filter(clean_text__startswith=params['word']).random() + lineTwo = lineOne.rhyming_lines().random() + return{'lines': [lineOne.text, lineTwo.text], "word": params['word']} + except Line.DoesNotExist: + raise NotFound("No lines start with that word or rhyme with one that does") + +