diff --git a/package.json b/package.json index 45941fb..45e3c81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clerkent", - "version": "3.6.0", + "version": "3.6.1", "private": true, "description": "quick search legal search", "repository": "https://github.com/lacuna-technologies/clerkent.git", diff --git a/src/manifest.json b/src/manifest.json index 0886d29..e395695 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -23,6 +23,7 @@ "*://www.commonlii.org/*", "*://www.hklii.hk/*", "*://www.hklii.org/*", + "*://www.icj-cij.org/*", "*://www.nzlii.org/*", "*://www.worldlii.org/*", "*://www6.austlii.edu.au/*", @@ -42,7 +43,6 @@ "https://www.caselaw.nsw.gov.au/*", "https://www.elitigation.sg/*", "https://www.epo.org/law-practice/case-law-appeals/*", - "https://www.icj-cij.org/*", "https://www.ipo.gov.uk/*", "https://www.ipos.gov.sg/*", "https://www.lawlibrary.vic.gov.au/*", diff --git a/src/utils/scraper/UN/ICJCIJ.ts b/src/utils/scraper/UN/ICJCIJ.ts index 2e1b3c8..af6f9b6 100644 --- a/src/utils/scraper/UN/ICJCIJ.ts +++ b/src/utils/scraper/UN/ICJCIJ.ts @@ -2,16 +2,10 @@ import request from '../../Request' import * as cheerio from 'cheerio' import Constants from '../../Constants' import { sortByName } from '../utils' +import Logger from 'utils/Logger' const BASE_URL = `https://www.icj-cij.org` -type Document = { - casename: string, - caseurl: string, - docname: string, - docurl: string -} - const getDocumentTypeFromDocumentName = (docname: string): Law.Link[`doctype`] | null => { const cleanDocname = docname.toLowerCase() if(cleanDocname.includes(`order`)){ @@ -24,23 +18,18 @@ const getDocumentTypeFromDocumentName = (docname: string): Law.Link[`doctype`] | return null } -const getAllCases = async () => { - const { data } = await request.get(`${BASE_URL}/en/decisions/all/1946/2021/desc`) +const getAllCases = async (): Promise => { + const year = (new Date()).getFullYear() + const { data } = await request.get(`${BASE_URL}/en/decisions?type=1&from=1946&to=${year}&sort_bef_combine=order_DESC`) const $ = cheerio.load(data) - return $(`.row > .col-sm-12 > .docket-odd`).map((_, element): Document => { - return { - casename: $(`h5:nth-of-type(2)`, element).text().trim().replace(`\n`, ``), - caseurl: $(`h5:nth-of-type(2) > a`, element).attr(`href`), - docname: $(`h4.docket`, element).text().trim().replace(`\n`, ``), - docurl: `${BASE_URL}${$(`h4.docket > a`, element).attr(`href`)}`, - } - }).get().map(({ - casename, - caseurl, - docname, - docurl, - }): Law.Case | null => { + return $(`.view-judgments-advisory-opinions-and-orders > .view-content.row > .views-row`).map((_, element): Law.Case | null => { + const name = $(`.views-field.views-field-field-case-long-title a`, element).text().trim().replace(`\n`, ``) + const details = $(`.views-field.views-field-field-icj-document-subtitle p`, element).text().trim() + const caseName = name + (details.length > 0 ? ` - ${details}` : ``) + const docname = $(`.views-field.views-field-field-document-long-title a`, element).text().trim().replace(`\n`, ``) const doctype = getDocumentTypeFromDocumentName(docname) + const summaryURL = BASE_URL + $(`.views-field.views-field-field-case-long-title a`, element).attr(`href`) + const documentURL = BASE_URL + $(`.views-field.views-field-field-document-long-title a`, element).attr(`href`) if(doctype === null){ return null } @@ -52,21 +41,23 @@ const getAllCases = async () => { { doctype: `Summary`, filetype: `HTML`, - url: caseurl, + url: summaryURL, }, { doctype, filetype: `PDF`, - url: docurl, + url: documentURL, }, ], - name: casename, + name: caseName, } - }).filter((c) => c !== null) + + }).get().filter((c) => c !== null) } const getCaseByName = async (caseName: string): Promise => { const cases = await getAllCases() + Logger.log(`Cases: `, cases) return sortByName(caseName, cases).slice(0, 20) }