From c80f9e3adc1b44e09dac63af555b64a6aabafd8e Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 29 May 2024 02:38:34 -0700 Subject: [PATCH 1/4] professor search component --- scraper/main.py | 12 +++ .../scrapers/__pycache__/rmp.cpython-311.pyc | Bin 0 -> 1781 bytes scraper/scrapers/rmp.py | 74 +++++++++++++++++ scraper/scrapers/tempCodeRunnerFile.py | 5 ++ scraper/tempCodeRunnerFile.py | 7 ++ src/lib/components/ProfessorSearch.svelte | 76 ++++++++++++++++++ src/lib/forms/schema.ts | 5 ++ src/routes/+layout.server.ts | 18 ++++- src/routes/+page.svelte | 5 +- 9 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 scraper/main.py create mode 100644 scraper/scrapers/__pycache__/rmp.cpython-311.pyc create mode 100644 scraper/scrapers/rmp.py create mode 100644 scraper/scrapers/tempCodeRunnerFile.py create mode 100644 scraper/tempCodeRunnerFile.py create mode 100644 src/lib/components/ProfessorSearch.svelte diff --git a/scraper/main.py b/scraper/main.py new file mode 100644 index 0000000..1ecf8cc --- /dev/null +++ b/scraper/main.py @@ -0,0 +1,12 @@ +from scrapers import rmp + +def main(): + rmp_professors = rmp.get_professors() # Assuming rmp.get_professors() retrieves data + #print(rmp_professors) + if rmp_professors: + print("RMP Professors:") + for professor in rmp_professors: + print(professor) + else: + print("No professor data found in the response.") +main() \ No newline at end of file diff --git a/scraper/scrapers/__pycache__/rmp.cpython-311.pyc b/scraper/scrapers/__pycache__/rmp.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..39f392263ac54b9f3f0e599da35ef2f680f0af9a GIT binary patch literal 1781 zcmZ`(&1)M+6dy?|SyC*oLq+0*v}}`-S~QVdH$6l+1vhfBODsE<0R-<88OG*1yh#Al!)BL1R}1d4w60z@e)BuGMJg7`>y zPazQ!C1>^m#UPpd3Kc`dmqUrzD+!a`ovjMd|2YIST{dbBCpmk8^w9 zjV81&VFY)lrZtncJQO#oX~|^r4d5kjO6kLTA@dOdh)%Q@mNlm1~TPv^IZD!(~BPTDyGNBd%$bR45ftOaxTr&@hoo8qv-f1{2$y&f-TE7$R>V3 z7c01Cu2ZJN_IWfjwQ{+p!|L0|wpOAZr*aaL&?aU=o`X{p$GM)I=5Dea0O<|Pg=@lk zqEQF!PUq*d*4F$@erL0CWA*N>Tbl_*UWXmwguVS+$vELMHVj!jXL7`0CG*M$*UXu@ zfA915{d-1zYyM-qSjf)d!cBXvzOtJLI6?QkIYC|SvlG&723Jp)w{s{VFaq!${toIX z5)yJC^&?v-!x%zB&KQUY4=n_5#hzcdZ;KZblcT<}|7ZVm$nrvFa;1YFp=T3AZ@hgD z&Wob}30xT2%9tG-vqK}h<9j4upowh4&(6S1C$f!M4R0BgC;X05=a%Ux*cMesAy{B1 zcO)l%~anGqJI{UdnIWadDX{!DEa0&E--)x3rO6TwNNt z>x;QuVQnMBreO#q1svYAOio!G0vz5rq-n1gQ+bH+)E2NajhdaxSh_8b7Ef_`%CLDI z9>^x<;Op>8QZ{UPiZz3se8$>Z;~57evAb`I3JUoIY~3%?Z()TQon zKa3{h-L*r2gtD@8(6AY)WX;({sbrnqdbkXJLhKzGxCH8Tc%fkt+n}E?4P1GicpX$f z;Pd%CIf~M}kwKK9Xt@O{u-9 Y+5Xu`%-=_#x{-c7 + export interface Professor { + id: number; + name: string; + } + + + + +
+ +
+ {#if suggestions.length > 0} +
    + {#each suggestions.slice(0, 5) as suggestion} +
  • + +
  • + {/each} +
+ {/if} +
+
diff --git a/src/lib/forms/schema.ts b/src/lib/forms/schema.ts index 5525626..9d7b27c 100644 --- a/src/lib/forms/schema.ts +++ b/src/lib/forms/schema.ts @@ -5,4 +5,9 @@ export const searchSchema = z.object({ courseNumber: z.string() }); +export const profSearchSchema = z.object({ + profName: z.string() +}); + export type SearchSchema = typeof searchSchema; +export type ProfSearchSchema = typeof profSearchSchema; diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index 320b237..c4d0a41 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -2,11 +2,12 @@ import { type RequestEvent } from '@sveltejs/kit'; import type { PageServerLoad } from './$types'; import { db } from '$lib/db/db.server'; -import { coursesTable } from '$lib/db/schema'; +import { coursesTable, professorsTable } from '$lib/db/schema'; import { asc } from 'drizzle-orm'; import { superValidate } from 'sveltekit-superforms'; import { zod } from 'sveltekit-superforms/adapters'; import { searchSchema } from '$lib/forms/schema'; +import { profSearchSchema } from '$lib/forms/schema'; export const load: PageServerLoad = async (event: RequestEvent) => { const result = await db @@ -20,13 +21,24 @@ export const load: PageServerLoad = async (event: RequestEvent) => { .from(coursesTable) .orderBy(asc(coursesTable.courseNumber)); + const profData = await db + .select({ + id: professorsTable.id, + name: professorsTable.name + }) + .from(professorsTable); + const form = await superValidate(zod(searchSchema)); + const profForm = await superValidate(zod(profSearchSchema)); + if (event.locals.user) { return { user: event.locals.user, form, - allCourseData: result + profForm, + allCourseData: result, + professorData: profData }; } - return { form, allCourseData: result }; + return { form, profForm, allCourseData: result, professorData: profData }; }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index b698929..8c10a86 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,11 +1,14 @@
+
From 47846cd64875d7b98b3a2cb87c3be65e87a4b898 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 5 Jun 2024 03:19:40 -0700 Subject: [PATCH 2/4] implemented autocomplete --- src/lib/components/ProfessorSearch.svelte | 41 +++++++++++++++-------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/src/lib/components/ProfessorSearch.svelte b/src/lib/components/ProfessorSearch.svelte index 47c256e..378e9fc 100644 --- a/src/lib/components/ProfessorSearch.svelte +++ b/src/lib/components/ProfessorSearch.svelte @@ -35,24 +35,38 @@ } } - function selectProfessor(professor: Professor) { - $form.profName = professor.name; - suggestions = []; - } - function handleSubmit(event: KeyboardEvent) { - if (event.key === 'Enter') { - const inputValue = $form.profName.trim(); - if (inputValue.length > 0) { - const split = inputValue.replace(' ', '-'); - goto(`./professors/${split}`); - } + function handleSubmit(event: Event) { + //event.preventDefault(); + let inputValue = ''; + const inputElement = document.querySelector('input[list="profNames"]') as HTMLInputElement; + inputValue = inputElement.value.trim(); + if (inputValue.length > 0) { + const split = inputValue.replace(' ', '-'); + goto(`./professors/${split}`); } } + -
+ + + {#each suggestions as suggestion} + + {/each} + +
+ + From efb924e16e93aba343abf5757990da601de42555 Mon Sep 17 00:00:00 2001 From: liubrian267 Date: Thu, 6 Jun 2024 01:53:15 -0700 Subject: [PATCH 3/4] professor search --- src/lib/components/ProfessorSearch.svelte | 44 +++++------------------ src/routes/+page.server.ts | 5 +-- src/routes/dev-login/+page.svelte | 1 - 3 files changed, 12 insertions(+), 38 deletions(-) diff --git a/src/lib/components/ProfessorSearch.svelte b/src/lib/components/ProfessorSearch.svelte index 378e9fc..181b4f6 100644 --- a/src/lib/components/ProfessorSearch.svelte +++ b/src/lib/components/ProfessorSearch.svelte @@ -9,6 +9,7 @@ import type { ProfSearchSchema } from '$lib/forms/schema'; import { superForm, type Infer, type SuperValidated } from 'sveltekit-superforms'; import { goto } from '$app/navigation'; + import SuperDebug from 'sveltekit-superforms'; interface Props { professors: Professor[]; @@ -17,7 +18,7 @@ let { professors, profFormData }: Props = $props(); - const { form, enhance } = superForm(profFormData, { + const { form } = superForm(profFormData, { invalidateAll: false, resetForm: false }); @@ -35,55 +36,28 @@ } } - function handleSubmit(event: Event) { - //event.preventDefault(); - let inputValue = ''; - const inputElement = document.querySelector('input[list="profNames"]') as HTMLInputElement; - inputValue = inputElement.value.trim(); - if (inputValue.length > 0) { - const split = inputValue.replace(' ', '-'); - goto(`./professors/${split}`); - } + event.preventDefault(); + goto(`./professors/${$form.profName}`); } - -
+ {#each suggestions as suggestion} {/each} -
- + + + diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 9f21d7d..f685b77 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,6 +1,6 @@ import { redirect, type Actions } from '@sveltejs/kit'; import { zod } from 'sveltekit-superforms/adapters'; -import { searchSchema } from '$lib/forms/schema'; +import { profSearchSchema, searchSchema } from '$lib/forms/schema'; import { superValidate } from 'sveltekit-superforms'; import { db } from '$lib/db/db.server'; import { coursesTable } from '$lib/db/schema'; @@ -8,7 +8,8 @@ import { and, eq } from 'drizzle-orm'; export const load = async () => { const form = await superValidate(zod(searchSchema)); - return { form }; + const profForm = await superValidate(zod(profSearchSchema)); + return { form, profForm }; }; export const actions: Actions = { diff --git a/src/routes/dev-login/+page.svelte b/src/routes/dev-login/+page.svelte index 6b2379d..2e6d62e 100644 --- a/src/routes/dev-login/+page.svelte +++ b/src/routes/dev-login/+page.svelte @@ -1,6 +1,5 @@ From 356d305b746407c1015d3af07d7d7bed83cd3459 Mon Sep 17 00:00:00 2001 From: liubrian267 Date: Thu, 6 Jun 2024 01:53:41 -0700 Subject: [PATCH 4/4] remove debugger --- src/lib/components/ProfessorSearch.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/lib/components/ProfessorSearch.svelte b/src/lib/components/ProfessorSearch.svelte index 181b4f6..29b5d3a 100644 --- a/src/lib/components/ProfessorSearch.svelte +++ b/src/lib/components/ProfessorSearch.svelte @@ -9,7 +9,6 @@ import type { ProfSearchSchema } from '$lib/forms/schema'; import { superForm, type Infer, type SuperValidated } from 'sveltekit-superforms'; import { goto } from '$app/navigation'; - import SuperDebug from 'sveltekit-superforms'; interface Props { professors: Professor[]; @@ -60,4 +59,3 @@ -