Skip to content

Instantly share code, notes, and snippets.

@renoirb
Last active December 6, 2024 17:24
Show Gist options
  • Save renoirb/c531772238ab4cf42560cc00d3d97f70 to your computer and use it in GitHub Desktop.
Save renoirb/c531772238ab4cf42560cc00d3d97f70 to your computer and use it in GitHub Desktop.
Genaology tree stuff

Extract siblings, daughters and sons

From a person's Profile page.

var siblings = {};
var family = {};
var parents = [];
    
[...document.querySelectorAll('.family_relative')].forEach(i => {
    const relativeName = i.querySelector('.relative_name')?.textContent
    const relationship = i.querySelector('.relative_relationship')?.textContent
    const [ birth, death = null ] = i.querySelector('.relative_years').textContent.split('-').map(i => i.trim())
    const isDead = death !== null
    const relationshipString = relationship.replace(/(his|her) /i, '')
    const isSibling = /(brother|sister)/i.test(relationshipString)
    const isSpouse = /(husband|wife)/.test(relationship)
    const isParent = /(mother|father)/.test(relationship)
    const isChild = /(daughter|son)/.test(relationship)
    let row = `${relativeName}`
    let dates = []

    if (Number.parseInt(birth)) {
        dates.push(birth)
    }
    
    if (isDead) {
        let d = ''
        if (Number.parseInt(death)) {
            d += `deceased ${death}`;
        } else {
            d += `deceased`;
        }
        if (d !== '') {
            dates.push(d)
        }
    }

    if(dates.length >= 1) {
        row += ' (' + dates.join(', ') + ')'
    }
    
    if (isSibling) {
        const s = Reflect.get(siblings, relationshipString) ?? []
        s.push(row)
        Reflect.set(siblings, relationshipString, s)
    } else if (isChild) {
        const s = Reflect.get(family, relationshipString) ?? []
        s.push(row)
        Reflect.set(family, relationshipString, s)
    } else if (isSpouse) {
        const s = Reflect.get(family, 'spouse') ?? []
        s.push(row)
        Reflect.set(family, 'spouse', s)
    } else if (isParent) {
        const deathText = (death === null) ? '~' : death
        const parent = {
            name: relativeName,
            birth,
            birthplace: "~",
            death: deathText,
            deathplace: "~",
            parents: [],
        }
        parents.push(parent)
    }
    
    console.log({row,  relativeName, relationshipString, relationship, birth, death, isDead, isSibling, isSpouse, isParent })
})
copy({family, siblings, parents})

Example output

family:
  spouse:
    - 'Delina Marie Chauvette (1880, deceased 1939)'
  son:
    - 'Joseph Alfred Boulanger (1900, deceased 1905)'
    - 'Alphonse Boulanger (1902, deceased 1970)'
    - 'Oscar Henri Boulanger (1905, deceased 1970)'
    - 'Alfred Louis Boulanger (1910, deceased)'
    - 'Omer Boulanger (1920, deceased)'
  daughter:
    - 'Marie Rosina Boulanger (1903, deceased 1978)'
    - 'Rose Eva Boulanger (1909, deceased)'
    - 'Dorilla Boulanger (1912, deceased 1998)'
    - 'Rose Aimée Boulanger (1917, deceased 1997)'
    - Demerise Rose Eva Boulanger
siblings:
  sister:
    - 'Rosina Rose Anna Marie Boulanger (1877, deceased 1962)'
    - 'Emma Claudia Boulanger (1883, deceased 1921)'
    - 'Louise Anna Boulanger (1885, deceased 1973)'
    - 'Philomene Boulanger (1892, deceased 1982)'
    - 'Josephine Flora Boulanger (1893, deceased 1934)'
    - 'Demerise Boulanger (1896, deceased 1922)'
    - Virginia Marie Boulanger
  brother:
    - 'Alfred  Adelard Boulanger (1882, deceased)'
    - 'Anonyme Boulanger (1887, deceased 1887)'
    - 'Henri Honore Boulanger (1888, deceased 1945)'
    - 'Napoleon Josephat Adelard Boulanger (1891, deceased 1891)'
@hosamn
Copy link

hosamn commented Dec 6, 2024

This looks interesting, can you give some context?!

@renoirb
Copy link
Author

renoirb commented Dec 6, 2024

This is code I’ve written to extract information on MyHeritage.com using developer console JavaScript. There’s more, I’m surprised I forgot the rest. I used this to get all my family up to 5 generations up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment