From f48fd76531124010c1a09ec5f5e204f746720b6e Mon Sep 17 00:00:00 2001 From: jkissane2 Date: Fri, 6 Mar 2026 12:01:34 -0500 Subject: [PATCH] Poems App --- notes.md | 2 +- poem_server/app/views.py | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/notes.md b/notes.md index 7425f84..6fc3f25 100644 --- a/notes.md +++ b/notes.md @@ -9,7 +9,7 @@ Some advantages of using a program or app which uses a remote server is that you can use/access the program or app from any device as long as you have an internet connection. Another great thing is that any changes you make or any data that you have will sync and save across multiple devices. - On the other hand, some advantages of using a program or app which is completlely local is being able to work offline. For example, if you are having difficulty connecting to the internet or have no internet access you can still use the program or app. I also did some researching about privacy concerns and it looks like the local servers increase privacy because the information would only be stored on your own computer- which makes complete sense! + On the other hand, some advantages of using a program or app which is completlely local is being able to work offline. For example, if you are having difficulty connecting to the internet or have no internet access you can still use the program or app. I also did some research about privacy concerns and it looks like the local servers increase privacy because the information would only be stored on your own computer- which makes complete sense! diff --git a/poem_server/app/views.py b/poem_server/app/views.py index 9a20b83..632ca80 100644 --- a/poem_server/app/views.py +++ b/poem_server/app/views.py @@ -6,3 +6,51 @@ 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): + lines = Line.objects.filter(text__icontains=params['topic']) + if not lines: + raise NotFound("No lines found about that topic") + return {'line': choice(lines).text, 'topic': params['topic'] } + +@route_get('lines/rhyme', args={'word': str}) +def get_lines_rhyme(params): + rhymes = Rhyme.get_rhyme_for_word(params['word']) + lines = list(rhymes.lines.all()) + if not rhymes: + raise NotFound("No rhymes found for that word") + line=choice(lines) + return {'line': line.text, 'word': params['word'] } + +@route_get('couplets/random', args={}) +def get_random_couplet(params): + poem= Poem.objects.random() + lines= sample(list(poem.lines.all()), 2) + return {'lines': [lines[0].text, lines[1].text]} + +@route_get('couplets/about', args={'topic': str}) +def get_couplets_about(params): + lines = Line.objects.filter(text__icontains=params['topic']) + if not lines: + raise NotFound("No lines found about that topic") + line1 = choice(lines) + line2 = choice(line1.poem.lines.exclude(id=line1.id)) + return {'lines': [line1.text, line2.text], 'topic': params['topic'] } + +@route_get('couplets/rhyme', args={'word': str}) +def get_couplets_rhyme(params): + rhyme = Rhyme.get_rhyme_for_word(params['word']) + lines = list(rhyme.lines.all()) + if not lines: + raise NotFound("No rhymes found for that word") + line1 = choice(lines) + line2 = choice(rhyme.lines.exclude(id=line1.id)) + return {'lines': [line1.text, line2.text], 'word': params['word'] } + +@route_get('lines/lastword', args={'word': str}) +def get_lines_lastword(params): + lines = Line.objects.filter(clean_text__endswith=params['word']) + if not lines: + raise NotFound("No lines found that end with that word") + return {'line': choice(lines).text, 'word': params['word'] }