From 7301e096681268b0debf5fb41c04c30c7964aaa3 Mon Sep 17 00:00:00 2001 From: Cory Date: Mon, 6 May 2024 18:27:24 -0400 Subject: [PATCH] Checkpoint 3! I wrote views so that all the specified routes work. I still have to implement the exceptions though. Stay tuned! --- .DS_Store | Bin 0 -> 6148 bytes poem_server/.DS_Store | Bin 0 -> 6148 bytes poem_server/app/views.py | 26 ++++++++++++++++++++++++++ 3 files changed, 26 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..215541a8ebf19b59db9474743309e254a4053046 GIT binary patch literal 6148 zcmeHKL2uJA6n@?cO{s=@0BM&=mbg}>Y!lkFODNlcD?xAoRGKD&uq>{Ubk$T<%6a=S zyY83pUpT?{Y*%Vmh7bpYD!=Oad$!+~)L&vdCL+-rN6&~_MC8F4YY$NT!nmJ(#Wrk9 z9VqlQ3hK}qMXypdT*-C~P64OD|E2)XU5_$SR8mX}^EXUYh(2BzUcfs)v>_sD(g^u6 zW_lltm~uMjl4tz_>-x`F;iMQ@)=fA{lcMZ)zln{_+P(XAukJOykHHr;3Cck^E_#Ff zJ=fkSm4@?p5WY>~Nx${zrOL`dlEt|uBvFi%5ATvJQj?waDUd8)5G0vTkh{YpUoQH<0ns#UiVMavrJv;QIo(Lr)|sP9Ig=Dp~-oWXQ|3Q zBZJxVtP+}CV69A{kYhj>;UxWW@iZ*lp*EONKNN+`lF z1@kx0OMJh@MAg|^D`4MeuesKvbc1sWI0gPj0bU;@oYA*f8PrP$3Vj3s*3hgCF@G{J zM_TkPRtC`n6NU;jRAG-8!qCw!ZJuwjGHB=|?BPS$I}3Y45&G`9zSQX?e1ooZ3OEIp z71%V@7VrNjcc1^4Nv`G;a0;xI0-|;t9QQCJySJ_kj`vy#{{&~_yvm@aps?Gq4tOix chHFEga^Q^ZMHDv}_p@KK1rzB2 z1N6@pRU#0#<>4T>;*^Eea^7{8if6zt7RLcCJh%VMc|MA~(DIdzhz5Q4R(_ z#6qim=WfU8I7`l3|Gk{}Wl&bdFc=?lYhTJVysQV|>m;6xdiP(*tPGMY9xFl;#TfGD zAju**8Okb)3dQwxhtqYsqu%Oty1up5cQ>{-XMK0Ny*}u>n;Xw&v##^t(UYCM(Z}>8 zlV7yx0%wx4dj>DzD=H?NPyRSdWp<1RkM7bDNg6|qiV9kzV>)Z9A|7JYRaKTLf_f!9 zgclTpRnRG=lpq?F z^ts8VZ*y!kt=%dG%>HneZdKMcS*w6m;7=6b^TCBPdIoEa>gYhBo&dl$!pcxrKmS0N z13=GUtq~EJ&{UwN3iHGe=ItOf9sQmeUu)EK5^814V^$XCg(A$;L%3=<2~VRftpZko zrUEV9?D75o^4IVGCdsy}0#>Fz$=t2ilHv8wP@ dyb4!_K9?&%&tR<)5t#iEP%_xUD)3hoxB!GbljQ&a literal 0 HcmV?d00001 diff --git a/poem_server/app/views.py b/poem_server/app/views.py index 9a20b83..897e544 100644 --- a/poem_server/app/views.py +++ b/poem_server/app/views.py @@ -6,3 +6,29 @@ 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_random_line_about(params): + return {'line': Line.objects.filter(clean_text__contains=params['topic']).random().text} + +@route_get('lines/rhyme',args={'rhyme': str}) +def get_random_line_that_rhymes_with(params): + return {'line': Rhyme.get_rhyme_for_word(params['rhyme']).lines.exclude(clean_text__endswith=params['rhyme']).random().text} + +@route_get('couplets/random',args={}) +def get_random_couplet(params): + first_line=Line.objects.random() + second_line=first_line.rhyming_lines().random() + return {'lines': [first_line.text,second_line.text]} + +@route_get('couplets/about',args={'topic': str}) +def get_random_couplet_about(params): + first_line=Line.objects.filter(clean_text__contains=params['topic']).random() + second_line=first_line.rhyming_lines().random() + return {'lines': [first_line.text,second_line.text]} + +@route_get('couplets/rhyme',args={'rhyme': str}) +def get_random_couplet_that_rhymes_with(params): + first_line = Rhyme.get_rhyme_for_word(params['rhyme']).lines.exclude(clean_text__endswith=params['rhyme']).random() + second_line = first_line.rhyming_lines().random() + return {'lines': [first_line.text,second_line.text]}