Created
May 28, 2021 17:51
-
-
Save thesmart/6a088592dcc0887e78897d7772440a8b to your computer and use it in GitHub Desktop.
Extract lawyers from http://www.uscourts.cavc.gov/public_list.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extract() { | |
let EMAIL_REGEX = /[^@^\s]+@([^\s]+)/; | |
let resultsEl = document.getElementById("results"); | |
let data = resultsEl.innerHTML.split('<b>'); | |
data.shift(); data.shift(); | |
let entries = data.map(function(t) { | |
let fields = t.split('<br>'); | |
fields = fields.map(function(t) { | |
return t.replaceAll(/<[^>]+>/g, '') | |
.replaceAll(/\n/g, ''); | |
}); | |
let addressR = fields.find(function(t) { | |
return /([^,]+), CA/.test(t); | |
}); | |
let emailR = fields.find(function(t) { | |
return EMAIL_REGEX.exec(t); | |
}); | |
let name = fields[0]; | |
let address = `${fields[1]}\n${fields[2]}`; | |
let emailMatches = EMAIL_REGEX.exec(emailR) | |
let email = emailMatches ? emailMatches[0] : null; | |
let domain = emailMatches ? emailMatches[1] : null; | |
let city = addressR ? (/([^,]+),/.exec(addressR)[1]) : null; | |
let zip = addressR ? (/([\d]+)\s*$/.exec(addressR)[1]) : null; | |
return { name, email, domain, address, city, zip }; | |
}); | |
return entries; | |
} | |
function createDirectory(entries) { | |
let domains = new Map(); | |
entries.forEach(function(e) { domains.set(e.domain, 0) }); | |
entries.forEach(function(e) { domains.set(e.domain, domains.get(e.domain) + 1) }); | |
let domainsSorted = Array.from(domains.keys()); | |
domainsSorted.sort(function(a, b) { | |
return domains.get(b) - domains.get(a); | |
}); | |
return domainsSorted.map(function(d) { | |
return { | |
domain: d, | |
count: domains.get(d), | |
entries: entries.filter(function(e) { return e.domain === d }) | |
} | |
}); | |
} | |
let entries = extract(); | |
let dir = createDirectory(entries); | |
console.log(JSON.stringify(entries)); | |
console.log(JSON.stringify(dir)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment