Skip to content

Commit

Permalink
✨ new: use eLitigation database for SG
Browse files Browse the repository at this point in the history
  • Loading branch information
hueyy committed Jul 15, 2021
1 parent 6d659dd commit 605347c
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 4 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module.exports = {
{
allowList: {
Props: true,
eLitigation: true,
props: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/ContentScript/ContentScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
2 changes: 2 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*",
Expand Down Expand Up @@ -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/*",
Expand Down
5 changes: 5 additions & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
9 changes: 6 additions & 3 deletions src/utils/scraper/SG/SG.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import SGSC from './SGSC'
import eLitigation from './eLitigation'
import SLW from './SLW'
import Common from '../common'
import SSO from './SSO'
Expand All @@ -14,7 +15,8 @@ const getLegislation = SSO.getLegislation
const getCaseByName = async (caseName: string): Promise<Law.Case[]> => {
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),
]))
Expand All @@ -38,8 +40,9 @@ const getCaseByName = async (caseName: string): Promise<Law.Case[]> => {
const getCaseByCitation = async (citation: string, court: string): Promise<Law.Case[]> => {
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<Law.Case[]>) => value)
Expand Down
84 changes: 84 additions & 0 deletions src/utils/scraper/SG/eLitigation.ts
Original file line number Diff line number Diff line change
@@ -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<Law.Case[]> => {
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<Law.Case[]> => {
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

0 comments on commit 605347c

Please sign in to comment.