Skip to content

Commit

Permalink
Decode HTML in courses
Browse files Browse the repository at this point in the history
  • Loading branch information
ninest committed Feb 10, 2023
1 parent 2d08de9 commit 1e1d321
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
32 changes: 16 additions & 16 deletions .data/subjects.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
{ "code": "BIOL", "description": "Biology" },
{ "code": "BIOT", "description": "Biotechnology" },
{ "code": "BUSN", "description": "Business Administration" },
{ "code": "EXSC", "description": "Cardiopulmonary & Exercise Sci" },
{ "code": "EXSC", "description": "Cardiopulmonary & Exercise Sci" },
{ "code": "CHME", "description": "Chemical Engineering" },
{ "code": "CHEM", "description": "Chemistry & Chemical Biology" },
{ "code": "CHEM", "description": "Chemistry & Chemical Biology" },
{ "code": "CHNS", "description": "Chinese" },
{ "code": "CIVE", "description": "Civil & Environmental Engineer" },
{ "code": "CIVE", "description": "Civil & Environmental Engineer" },
{ "code": "COMM", "description": "Communication Studies" },
{ "code": "CS", "description": "Computer Science" },
{ "code": "EEAM", "description": "Coop/Exper Ed - Arts/Med/Dsgn" },
Expand All @@ -27,9 +27,10 @@
{ "code": "INNO", "description": "Corporate Innovation" },
{ "code": "CAEP", "description": "Counseling and Applied Ed Psyc" },
{ "code": "CRIM", "description": "Criminal Justice" },
{ "code": "CLTR", "description": "Culture" },
{ "code": "CY", "description": "Cybersecurity" },
{ "code": "DS", "description": "Data Science" },
{ "code": "ENVR", "description": "Earth & Environmental Sciences" },
{ "code": "ENVR", "description": "Earth & Environmental Sciences" },
{ "code": "ECON", "description": "Economics" },
{ "code": "EECE", "description": "Electrical and Comp Engineerng" },
{ "code": "ENSY", "description": "Energy Systems" },
Expand All @@ -38,8 +39,8 @@
{ "code": "EMGT", "description": "Engineering Management" },
{ "code": "ENGL", "description": "English" },
{ "code": "ENGW", "description": "English Writing" },
{ "code": "ENTR", "description": "Entrepreneurship & Innovation" },
{ "code": "FINA", "description": "Finance & Insurance" },
{ "code": "ENTR", "description": "Entrepreneurship & Innovation" },
{ "code": "FINA", "description": "Finance & Insurance" },
{ "code": "GE", "description": "General Engineering" },
{ "code": "HINF", "description": "Health Informatics" },
{ "code": "HLTH", "description": "Health Sci - Interdisciplinary" },
Expand All @@ -58,7 +59,7 @@
{ "code": "MGSC", "description": "Management Science" },
{ "code": "MKTG", "description": "Marketing" },
{ "code": "MATH", "description": "Mathematics" },
{ "code": "MEIE", "description": "Mech & Industrial Engineering" },
{ "code": "MEIE", "description": "Mech & Industrial Engineering" },
{ "code": "ME", "description": "Mechanical Engineering" },
{ "code": "MSCR", "description": "Media and Screen Studies" },
{ "code": "MUSC", "description": "Music" },
Expand All @@ -76,21 +77,23 @@
{ "code": "PPUA", "description": "Pub Policy and Urban Affairs" },
{ "code": "PHTH", "description": "Public Health" },
{ "code": "SOCL", "description": "Sociology" },
{ "code": "SLPA", "description": "Speech-Lang Path & Audiology" },
{ "code": "SLPA", "description": "Speech-Lang Path & Audiology" },
{ "code": "STRT", "description": "Strategy" },
{ "code": "SCHM", "description": "Supply Chain Management" },
{ "code": "THTR", "description": "Theatre" },
{ "code": "AMSL", "description": "American Sign Language" },
{ "code": "ARTS", "description": "Art - Studio" },
{ "code": "AACE", "description": "Arts Admin & Cultural Entrep" },
{ "code": "EEMB", "description": "Ecology, Evolutn & Marine Biol" },
{ "code": "AACE", "description": "Arts Admin & Cultural Entrep" },
{ "code": "DAMG", "description": "Data Architecture Management" },
{ "code": "EEMB", "description": "Ecology, Evolutn & Marine Biol" },
{ "code": "ENLR", "description": "Engineering Leadership" },
{ "code": "TECE", "description": "Entrepreneurship Technological" },
{ "code": "FRNH", "description": "French" },
{ "code": "GAME", "description": "Game Design" },
{ "code": "GRMN", "description": "German" },
{ "code": "HSCI", "description": "Health Science" },
{ "code": "HRMG", "description": "Human Resources Management" },
{ "code": "INFO", "description": "Information Systems Program" },
{ "code": "INTB", "description": "International Business" },
{ "code": "JPNS", "description": "Japanese" },
{ "code": "JWSS", "description": "Jewish Studies" },
Expand All @@ -100,8 +103,9 @@
{ "code": "SPNS", "description": "Spanish" },
{ "code": "ABRU", "description": "Study USA" },
{ "code": "SUEN", "description": "Sustainable Urban Environments" },
{ "code": "WMNS", "description": "Women's/Gender/Sexualty Stdies" },
{ "code": "WMNS", "description": "Women's/Gender/Sexualty Stdies" },
{ "code": "CMMN", "description": "Communicatn Studies - CPS Spec" },
{ "code": "CSYE", "description": "Computer Systems Engineering" },
{ "code": "DA", "description": "Data Analytics" },
{ "code": "ESLG", "description": "English as Scnd Lng - CPS Spec" },
{ "code": "NETS", "description": "Network Science" },
Expand All @@ -118,9 +122,6 @@
{ "code": "ASNS", "description": "Asian Studies" },
{ "code": "BNSC", "description": "Behavioral Neuroscience" },
{ "code": "BIOC", "description": "Biochemistry" },
{ "code": "CSYE", "description": "Computer Systems Engineering" },
{ "code": "CLTR", "description": "Culture" },
{ "code": "DAMG", "description": "Data Architecture Management" },
{ "code": "DEAF", "description": "Deaf Studies" },
{ "code": "ECNM", "description": "Economics - CPS Spec" },
{ "code": "EDUC", "description": "Education" },
Expand All @@ -131,13 +132,12 @@
{ "code": "GBST", "description": "Global Studies - CPS Spec" },
{ "code": "HBRW", "description": "Hebrew" },
{ "code": "IS", "description": "Information Science" },
{ "code": "INFO", "description": "Information Systems Program" },
{ "code": "INAM", "description": "Interdisc Studies - Arts/Media" },
{ "code": "INSC", "description": "Interdisc Studies - Science" },
{ "code": "INTP", "description": "Interpreting" },
{ "code": "ITLN", "description": "Italian" },
{ "code": "LARC", "description": "Landscape Architecture" },
{ "code": "LACS", "description": "Latin Am & Carib Studies" },
{ "code": "LACS", "description": "Latin Am & Carib Studies" },
{ "code": "LAW", "description": "Law" },
{ "code": "LW", "description": "Law (for Non-Law School Stu)" },
{ "code": "MATL", "description": "Materials Engineering" },
Expand Down
5 changes: 3 additions & 2 deletions banner/subject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Subject, Term } from "@/types.ts";
import { dedup } from "@/util/dedup.ts";
import { decodeHTML } from "../util/decode-html.ts";

// Requires terms to be passed in
export const getAllSubjects = async (terms: Term[]): Promise<Subject[]> => {
Expand All @@ -8,7 +9,7 @@ export const getAllSubjects = async (terms: Term[]): Promise<Subject[]> => {
const subjectsToAdd = await getSubjects(term.code);
subjectsToAdd.forEach((subject) => {
if (!subjects.some((s) => s.code === subject.code)) {
subjects.push(subject);
subjects.push({ ...subject, description: decodeHTML(subject.description) });
}
});
}
Expand All @@ -21,7 +22,7 @@ export const getAllSubjects = async (terms: Term[]): Promise<Subject[]> => {
export const getSubjects = async (term: string): Promise<Subject[]> => {
// TODO: use URLSearchParams
const response = await fetch(
`https://nubanner.neu.edu/StudentRegistrationSsb/ssb/classSearch/get_subject?searchTerm=&term=${term}&offset=1&max=400`, // 400 to get all
`https://nubanner.neu.edu/StudentRegistrationSsb/ssb/classSearch/get_subject?searchTerm=&term=${term}&offset=1&max=400` // 400 to get all
);
const terms = await response.json();
return terms;
Expand Down
7 changes: 2 additions & 5 deletions util/decode-html.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.33-alpha/deno-dom-wasm.ts";

export const decodeHTML = (string: string): string => {
const document = new DOMParser().parseFromString(
`<textarea></textarea>`,
"text/html",
);
const document = new DOMParser().parseFromString(`<textarea></textarea>`, "text/html");
const textarea = document?.getElementsByTagName("textarea")[0];
textarea!.innerHTML = string;
const decoded = textarea?.innerText;
return decoded!.replaceAll("&#8217;", "'").replaceAll("#8217;", "'");
return decoded!.replaceAll("&#8217;", "'").replaceAll("#8217;", "'").replaceAll("&amp;", "&");
};

0 comments on commit 1e1d321

Please sign in to comment.