Skip to content

Commit

Permalink
Scrape professors in an additional request
Browse files Browse the repository at this point in the history
  • Loading branch information
mehallhm committed Nov 19, 2024
1 parent 3597a33 commit af0b100
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
Binary file added .yarn/install-state.gz
Binary file not shown.
10 changes: 6 additions & 4 deletions infrastructure/dev/docker-compose-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ services:
- ./docker-postgresql-multiple-databases:/docker-entrypoint-initdb.d
- pg:/var/lib/postgresql/data
environment:
- POSTGRES_MULTIPLE_DATABASES=searchneu_dev,searchneu_test
- POSTGRES_USER=postgres
POSTGRES_MULTIPLE_DATABASES: searchneu_dev,searchneu_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: default_password
es:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
ports:
Expand All @@ -22,12 +23,12 @@ services:
depends_on:
- es
- postgresql
command: yarn prod
ports:
- 4000:4000
- 8080:8080
environment:
DATABASE_URL: postgresql://postgres@postgresql:5432/searchneu_dev
DATABASE_URL: postgresql://postgres:default_password@postgresql:5432/searchneu_dev
POSTGRES_PASSWORD: default_password
elasticURL: http://es:9200
TWILIO_PHONE_NUMBER:
TWILIO_ACCOUNT_SID:
Expand All @@ -36,5 +37,6 @@ services:
CLIENT_ORIGIN: http://localhost:5000
JWT_SECRET:
SLACK_WEBHOOK_URL:

volumes:
pg:
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@babel/node": "^7.0.0",
"@babel/register": "^7.0.0",
"@elastic/elasticsearch": "7.17.0",
"@prisma/client": "^5.0.0",
"@prisma/client": "5.22.0",
"@typescript-eslint/typescript-estree": "^8.10.0",
"amplitude": "^6.0.0",
"apollo-server": "^3.13.0",
Expand Down
27 changes: 24 additions & 3 deletions scrapers/classes/parsersxe/termParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,31 @@ class TermParser {
);

const bodyObj = JSON.parse(req.body);
if (bodyObj.success) {
return { items: bodyObj.data, totalCount: bodyObj.totalCount };

if (!bodyObj.success) {
return false;
}
return false;

bodyObj.data = await Promise.all(
bodyObj.data.map(async (sr: SectionSR) => {
const resp = await request.get(
"https://nubanner.neu.edu/StudentRegistrationSsb/ssb/searchResults/getFacultyMeetingTimes",
{
searchParams: {
term: termId,
courseReferenceNumber: sr.courseReferenceNumber,
},
},
);

const body = await JSON.parse(resp.body);
sr.faculty = body.fmt[0]?.faculty ?? [];

return sr;
}),
);

return { items: bodyObj.data, totalCount: bodyObj.totalCount };
})) as SectionSR[];
} catch (error) {
macros.error(`Could not get section data for ${termId}`);
Expand Down
18 changes: 3 additions & 15 deletions services/dumpProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class DumpProcessor {
convertSectionToPrismaType(section),
);
await this.saveSectionsToDatabase(processedSections);
await this.updateSectionsLastUpdateTime(termDump.sections);

await this.saveSubjectsToDatabase(termDump.subjects);

Expand Down Expand Up @@ -131,7 +130,10 @@ class DumpProcessor {

for (const sections of groupedSections) {
const upsertQueries = sections.map((prismaSection) => {
// Updates thelast update time for tracking sections that haven't been updated
// in a while for eventual removal
prismaSection.lastUpdateTime = updateTime;

return prisma.section.upsert({
create: prismaSection,
update: prismaSection,
Expand All @@ -148,20 +150,6 @@ class DumpProcessor {
macros.log("Finished with sections");
}

/**
* Update the lastUpdateTime attribute on all given sections.
* We use this to track sections that haven't been updated in a while,
* which means that they're no longer on Banner & should be removed from our database.
*/
async updateSectionsLastUpdateTime(sections: Section[]): Promise<void> {
await prisma.course.updateMany({
where: { id: { in: sections.map((s) => keys.getClassHash(s)) } },
data: { lastUpdateTime: new Date() },
});

macros.log("Finished updating times");
}

/**
* Saves all subject data to the database. This does NOT delete existing subjects, but will
* overwrite the data if there is any new data for those subjects.
Expand Down

0 comments on commit af0b100

Please sign in to comment.