Skip to content

Instantly share code, notes, and snippets.

@dadatuputi
Created June 17, 2020 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadatuputi/3f74c63a1e71995aa72627930bd9451e to your computer and use it in GitHub Desktop.
Save dadatuputi/3f74c63a1e71995aa72627930bd9451e to your computer and use it in GitHub Desktop.
Ancestor Names
from gedcom.element.individual import IndividualElement
from gedcom.parser import Parser
file_path = 'temp.ged'
gedcom_parser = Parser()
gedcom_parser.parse_file(file_path)
root_child_elements = gedcom_parser.get_root_child_elements()
first_names = {}
last_names = {}
# Iterate through all root child elements
for element in root_child_elements:
# Is the `element` an actual `IndividualElement`? (Allows usage of extra functions such as `surname_match` and `get_name`.)
if isinstance(element, IndividualElement):
# Unpack the name tuple
(firsts, last) = element.get_name()
for first in firsts.split(' '):
value = 0
if first in first_names:
value = first_names[first] + 1
first_names[first] = value
value = 0
if last in last_names:
value = last_names[last] + 1
last_names[last] = value
first_names = sorted(first_names.items(), key=lambda x: x[1], reverse=True)
last_names = sorted(last_names.items(), key=lambda x: x[1], reverse=True)
with open('first.txt', 'w') as f:
for first, num in first_names:
f.write("{}: {}\n".format(first, num))
with open('last.txt', 'w') as f:
for last, num in last_names:
f.write("{}: {}\n".format(last, num))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment