Skip to content

Commit

Permalink
fix: 🐛 combine functions for entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-wang0 committed May 15, 2024
1 parent a9f4a39 commit 9b06d09
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions services/departments-terms-scraper/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { load } from "cheerio";
import { CheerioAPI, load } from "cheerio";
import fetch from "cross-fetch";

async function fetchWebSoc() {
Expand All @@ -7,9 +7,7 @@ async function fetchWebSoc() {
return load(body);
}

export async function getDepartments(): Promise<string[]> {
const $ = await fetchWebSoc();

async function getDepartments($: CheerioAPI): Promise<string[]> {
const departments: string[] = [];
$('select[name="Dept"] option').each((_index, element) => {
const deptText = $(element).text().trim();
Expand All @@ -22,9 +20,7 @@ export async function getDepartments(): Promise<string[]> {
return departments;
}

export async function getTerms(): Promise<string[]> {
const $ = await fetchWebSoc();

async function getTerms($: CheerioAPI): Promise<string[]> {
const terms: string[] = [];
$('select[name="YearTerm"] option').each((_index, element) => {
const termText = $(element).text().trim();
Expand All @@ -33,3 +29,14 @@ export async function getTerms(): Promise<string[]> {

return terms;
}

async function getDepartmentsTerms() {
const $ = await fetchWebSoc();

const terms = await getTerms($);
const departments = await getDepartments($);

return { departments, terms };
}

export default getDepartmentsTerms();

0 comments on commit 9b06d09

Please sign in to comment.