From 5226ec80d0050b23ec239569883f11a16a9e8860 Mon Sep 17 00:00:00 2001 From: Eric Jackson Date: Mon, 4 Nov 2024 17:41:56 -0500 Subject: [PATCH] Deleted old search and related libraries --- packages/server/package.json | 7 - packages/server/search-court-records_old.js | 153 -------------------- 2 files changed, 160 deletions(-) delete mode 100644 packages/server/search-court-records_old.js diff --git a/packages/server/package.json b/packages/server/package.json index ad98fcd..b2e3b3d 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -15,8 +15,6 @@ }, "dependencies": { "@fortawesome/fontawesome-free": "^6.5.1", - "axios": "^1.6.5", - "axios-cookiejar-support": "^4.0.7", "body-parser": "^1.20.2", "copy-to-clipboard": "^3.3.3", "dotenv": "^16.3.1", @@ -47,10 +45,5 @@ "eslint-plugin-react-hooks": "^4.6.0", "jest": "29.7.0", "supertest": "^6.3.3" - }, - "jest": { - "moduleNameMapper": { - "axios": "axios/dist/node/axios.cjs" - } } } diff --git a/packages/server/search-court-records_old.js b/packages/server/search-court-records_old.js deleted file mode 100644 index 2c4b891..0000000 --- a/packages/server/search-court-records_old.js +++ /dev/null @@ -1,153 +0,0 @@ -const { JSDOM } = require('jsdom'); -const axios = require('axios'); -const { wrapper } = require('axios-cookiejar-support'); -const { CookieJar } = require('tough-cookie'); -const { CourtCase } = require('./court-case'); - -const maxPages = 50; - -function createCaseFromHtml(tr) { - const mapped = []; - - for (let i = 0; i < tr.children.length; i += 1) { - const td = tr.children[i]; - const text = td.textContent.trim(); - - if (i === 6) { - mapped.push([text, td.children[0].href]); - } else { - mapped.push(text); - } - } - - return CourtCase(mapped); -} - -function computeSearchUrl(state, start, navIndex, submit) { - let queryParams = `defendant=${state.lastName}`; - - if (state.firstName) queryParams += `%2C${state.firstName}`; - - if (state.middleName) queryParams += `%2C${state.middleName}`; - - return `https://www1.aoc.state.nc.us/www/calendars.Criminal.do?county=100&court=BTH+&${queryParams}&start=${start}&navindex=${navIndex}&fromcrimquery=yes&submit=${submit}`; -} - -async function getCasesPage(axiosInstance, url, cases) { - const resp = await axiosInstance.get(url, { withCredentials: true }); - const content = resp.data; - - const dom = new JSDOM(content); - const table = dom.window.document.querySelector('.criminalquery-table'); - - if (table) { - const rows = table.querySelectorAll('tbody > tr'); - if (rows.length > 0) { - rows.forEach((row) => { - cases.push(createCaseFromHtml(row)); - }); - } - } - - const nextPage = { - keepOn: false, - start: 0, - navindex: 0, - submit: 'Search', - }; - - // Check to see if there are more pages of results - const forms = dom.window.document.querySelectorAll('form'); - if (forms) { - forms.forEach((searchagain) => { - if (!nextPage.keepOn) { // Skip if we already found it - const inputs = searchagain.querySelectorAll('input'); - const formValues = {}; - inputs.forEach((ip) => { - if (ip.getAttribute('TYPE') === 'HIDDEN') { - formValues[ip.getAttribute('NAME')] = ip.getAttribute('VALUE'); - } - }); - if (formValues.submit === 'Next 25') { - nextPage.keepOn = true; - nextPage.start = formValues.start; - nextPage.navindex = formValues.navindex; - nextPage.submit = 'Next+25'; - } - } - }); - } - return nextPage; -} - -function sortByDefendant(a, b) { - if (a.defendant < b.defendant) { - return -1; - } - if (a.defendant < b.defendant) { - return 1; - } - return 0; -} - -async function searchCourtRecords(body, callback) { - const jar = new CookieJar(); - const axiosInstance = wrapper(axios.create({ jar })); - - let url = computeSearchUrl(body, 0, 0, 'Search'); - let cases = []; - let nextPage = await getCasesPage(axiosInstance, url, cases, false); - let { keepOn } = nextPage; - let count = 0; - - while (keepOn) { - url = computeSearchUrl(body, nextPage.start, nextPage.navindex, nextPage.submit); - // eslint-disable-next-line no-await-in-loop - nextPage = await getCasesPage(axiosInstance, url, cases); - keepOn = nextPage.keepOn; - count += 1; - if (count > maxPages) keepOn = false; - } - const defendants = {}; - cases.forEach((item) => { - const defendantID = `${item.defendant}.${item.dob}`; - if (!(defendantID in defendants)) { - defendants[defendantID] = []; - } - defendants[defendantID].push(item); - }); - - cases = []; - const keys = Object.keys(defendants); - keys.forEach((item) => { - const caselist = defendants[item]; - const first = caselist[0]; - const d = { - defendant: first.defendant, - dob: first.dob, - cases: caselist.map((c) => { - const detailsUrl = new URL(c.linkToCaseDetails); - detailsUrl.searchParams.delete('prev'); - return { - court: c.court, - courtDate: c.courtDate, - courtRoom: c.courtRoom, - session: c.session, - caseNumber: c.caseNumber, - linkToCaseDetails: detailsUrl.toString(), - citationNumber: c.citationNumber, - }; - }), - }; - cases.push(d); - }); - cases = cases.sort(sortByDefendant); - if (callback !== null) { - callback(cases); - } - return cases; -} - -module.exports = { - searchCourtRecords, -};