From 605347c35ccc0d22ba89d74ae84ac9859ec36e48 Mon Sep 17 00:00:00 2001 From: Huey Date: Thu, 15 Jul 2021 14:42:06 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20new:=20use=20eLitigation=20database?= =?UTF-8?q?=20for=20SG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 1 + package.json | 2 +- src/ContentScript/ContentScript.tsx | 1 + src/manifest.json | 2 + src/utils/Constants.ts | 5 ++ src/utils/scraper/SG/SG.ts | 9 ++-- src/utils/scraper/SG/eLitigation.ts | 84 +++++++++++++++++++++++++++++ 7 files changed, 100 insertions(+), 4 deletions(-) create mode 100644 src/utils/scraper/SG/eLitigation.ts diff --git a/.eslintrc.js b/.eslintrc.js index 73909b4..4d289fd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -88,6 +88,7 @@ module.exports = { { allowList: { Props: true, + eLitigation: true, props: true, }, }, diff --git a/package.json b/package.json index cb41e4e..5e1b1e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clerkent", - "version": "2.8.0", + "version": "2.8.1", "private": true, "description": "quick search for international caselaw and legislation", "repository": "https://github.com/lacuna-technologies/clerkent.git", diff --git a/src/ContentScript/ContentScript.tsx b/src/ContentScript/ContentScript.tsx index 8510321..11eec82 100644 --- a/src/ContentScript/ContentScript.tsx +++ b/src/ContentScript/ContentScript.tsx @@ -30,6 +30,7 @@ const onMessage = (message: Message) => { const highlightBlacklist = new Set([ `advance.lexis.com`, `app.justis.com`, + `www.elitigation.sg/*`, `curia.europa.eu`, `ejudgment.kehakiman.gov.my`, `eur-lex.europa.eu`, diff --git a/src/manifest.json b/src/manifest.json index 346884a..73101ad 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -33,6 +33,7 @@ "https://scc-csc.lexum.com/*", "https://sso.agc.gov.sg/*", "https://www.canlii.org/*", + "https://www.elitigation.sg/*", "https://www.epo.org/law-practice/case-law-appeals/*", "https://www.icj-cij.org/*", "https://www.legislation.gov.uk/*", @@ -194,6 +195,7 @@ "https://www-lawnet-sg.libproxy.smu.edu.sg/*", "https://www-lexisnexis-com.libproxy.ucl.ac.uk/*", "https://www.canlii.org/*", + "https://www.elitigation.sg/*", "https://www.epo.org/law-practice/case-law-appeals/*", "https://www.icj-cij.org/*", "https://www.lawnet.sg/*", diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index 5f03da9..3378450 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -60,6 +60,11 @@ const JURISDICTIONS = { const SG_DATABASES = { + elitigation: { + icon: ``, + name: `eLitigation`, + url: `https://www.elitigation.sg/gdviewer/Home/Index`, + }, lawnet: { icon: ``, name: `Lawnet`, diff --git a/src/utils/scraper/SG/SG.ts b/src/utils/scraper/SG/SG.ts index b36d5c6..0d82a7f 100644 --- a/src/utils/scraper/SG/SG.ts +++ b/src/utils/scraper/SG/SG.ts @@ -1,4 +1,5 @@ import SGSC from './SGSC' +import eLitigation from './eLitigation' import SLW from './SLW' import Common from '../common' import SSO from './SSO' @@ -14,7 +15,8 @@ const getLegislation = SSO.getLegislation const getCaseByName = async (caseName: string): Promise => { try { const results = (await Promise.allSettled([ - SGSC.getCaseByName(caseName), + eLitigation.getCaseByName(caseName), + // SGSC.getCaseByName(caseName), // SLW.getCaseByName(caseName), Common.CommonLII.getCaseByName(caseName, Constants.JURISDICTIONS.SG.name), ])) @@ -38,8 +40,9 @@ const getCaseByName = async (caseName: string): Promise => { const getCaseByCitation = async (citation: string, court: string): Promise => { try { const results = (await Promise.allSettled([ - SGSC.getCaseByCitation(citation), - SLW.getCaseByCitation(citation), + eLitigation.getCaseByName(citation), + // SGSC.getCaseByCitation(citation), + // SLW.getCaseByCitation(citation), Common.CommonLII.getCaseByCitation(citation), ])).filter(({ status }) => status === `fulfilled`) .flatMap(({ value }: PromiseFulfilledResult) => value) diff --git a/src/utils/scraper/SG/eLitigation.ts b/src/utils/scraper/SG/eLitigation.ts new file mode 100644 index 0000000..87933a0 --- /dev/null +++ b/src/utils/scraper/SG/eLitigation.ts @@ -0,0 +1,84 @@ +import cheerio from 'cheerio' +import Request from '../../Request' +import type Law from '../../../types/Law' +import Constants from '../../Constants' +import Logger from '../../Logger' + +const DOMAIN = `https://www.elitigation.sg` + +const parseCaseResults = (data: string): Law.Case[] => { + const $ = cheerio.load(data) + return $(`#listview > .row:nth-of-type(3) > .card.col-12`).map((_, element) => { + const card = $(`> .card-body > .row`, element) + const name = $(`a.gd-card-title`, card).text().trim() + const link = $(`a.gd-card-title`, card).attr(`href`) + const pdf = $(`img.card-icon`, card).parent().attr(`href`) + const citation = $(`span.gd-addinfo-text`, card).first().text().trim().replace(`|`, ``) + + const summaryLink = link + ? { doctype: `Summary`, filetype: `HTML`, url: `${DOMAIN}${link}` } + : null + + const pdfLink = pdf + ? { doctype: `Judgment`, filetype: `PDF`, url: `${DOMAIN}${pdf}` } + : null + + const results = { + citation, + database: Constants.DATABASES.SG_elitigation, + jurisdiction: Constants.JURISDICTIONS.SG.id, + links: [ + ...(summaryLink ? [summaryLink] : []), + ...(pdfLink ? [pdfLink] : []), + ], + name, + } + Logger.log(`eLitigation results`, results) + + return results + + }).get() +} + +const trimLeadingPageZeros = (citation: string) => citation.replace(/ 0+([1-9]+)$/, ` $1`) + +const getCaseByCitation = async (citation: string): Promise => { + const { data } = await Request.get(`${DOMAIN}/gdviewer/Home/Index`, + { + params: { + currentPage: `1`, + searchPhrase: citation, + sortAscending: `False`, + sortBy: `Score`, + verbose: false, + yearOfDecision: `All`, + }, + }) + + return parseCaseResults(data).filter(({ citation: scrapedCitation })=> ( + trimLeadingPageZeros(scrapedCitation).toLowerCase() === citation.toLowerCase() + )) +} + +const getCaseByName = async (caseName: string): Promise => { + const { data } = await Request.get(`${DOMAIN}/gdviewer/Home/Index`, + { + params: { + currentPage: `1`, + searchPhrase: caseName, + sortAscending: `False`, + sortBy: `Score`, + verbose: false, + yearOfDecision: `All`, + }, + }) + + return parseCaseResults(data) +} + +const eLitigation = { + getCaseByCitation, + getCaseByName, +} + +export default eLitigation \ No newline at end of file