Created
April 14, 2020 21:27
-
-
Save Narvey/cb96ce004d473c7d44104fc43d1055e5 to your computer and use it in GitHub Desktop.
Parsing of our church directory (I used this in the js scratchpad, but console should work too)
This file contains 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
contacts = [] | |
;[...document.getElementsByClassName("household")].forEach(div=> | |
{ | |
let names = [... div.getElementsByTagName("b")].map(e=>e.innerText) | |
let results = /(\w+)['’]s Cell ([-0-9]+)/.exec(div.innerText) | |
let surname = names[0] | |
if (surname.split(" ").length>1)//check for the unmarried | |
{ | |
surname = surname.split(" ")[1] //grab surname | |
console.log(surname) | |
} | |
else surname = names[1].split(" ")[1] | |
if(!/^\w+$/.test(surname)) surname = names[0].split() | |
if(results) | |
contacts.push({ | |
name: results[1] + " " + surname, | |
phone: results[2] | |
}) | |
else | |
contacts.push({ | |
name: surname, | |
phone: 0 | |
}) | |
}) | |
contacts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment