-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_2.py
32 lines (27 loc) · 1.1 KB
/
example_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
from ged4py.parser import GedcomReader
def example_2():
with GedcomReader(sys.argv[1]) as parser:
# iterate over each FAM record in a file
for i, fam in enumerate(parser.records0("FAM")):
print(f"{i}:")
# Get records for spouses, FAM record contains pointers to INDI
# records but sub_tag knows how to follow the pointers and return
# the referenced records instead.
husband, wife = fam.sub_tag("HUSB"), fam.sub_tag("WIFE")
if husband:
print(f" husband: {husband.name.format()}")
if wife:
print(f" wife: {wife.name.format()}")
# Get _value_ of the MARR/DATE tag
marr_date = fam.sub_tag_value("MARR/DATE")
if marr_date:
print(f" marriage date: {marr_date}")
# access all CHIL records, sub_tags method returns list (possibly empty)
children = fam.sub_tags("CHIL")
for child in children:
# print name and date of birth
print(f" child: {child.name.format()}")
birth_date = child.sub_tag_value("BIRT/DATE")
if birth_date:
print(f" birth date: {birth_date}")