From ad0f4ee655a024b9a3bafb96af8ebcb58edf9714 Mon Sep 17 00:00:00 2001 From: Thomas Naber Date: Sun, 5 May 2024 13:54:11 -0400 Subject: [PATCH] Checkpoint 3 --- .DS_Store | Bin 0 -> 6148 bytes poem_server/.DS_Store | Bin 0 -> 6148 bytes poem_server/app/views.py | 59 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 .DS_Store create mode 100644 poem_server/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..36e13713df7440d172483df4cc1abf92dd46d4ab GIT binary patch literal 6148 zcmeHK%SyvQ6g{^VsT8G4H$uK3;2*?N7q0sON|PXJOeEGqciHjdc`>wJ??Xldq~y|GCl>FU#v)8 zdrTJ1OaW8C6!?=0==YX3nR>L;6fgx$fmQ+iK16iIBw*vweL9%9D*$oKYG=&rFQamz zfJwl{BU@dtaK;_?uhYl%a=X5>;#J@&VrHyNnC;iLL0pQvfVyTmjO&;ssLc!1UOG})p;=82 zR;?Ceh}WZ?+UmMqI#RP8R>OzYoz15hnq@nzF`-!xQ4j$Um=RcIKKc27r2jVm&svm< zfC&6E0=7P!4tu^-ovjbA=k?dB`g+i*aXG_}p8zI)6mRKa+;6_1_R^8c3Qa!(fk8n8 H{*=Hspa&6( literal 0 HcmV?d00001 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") + +