Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_occupations in individual.py #65

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<p align="center">
<a href="https://pypi.org/project/python-gedcom/" target="_blank"><img src="https://img.shields.io/pypi/v/python-gedcom.svg" alt="PyPI"></a>
<a href="https://github.com/nickreynke/python-gedcom/releases" target="_blank"><img src="https://img.shields.io/github/release/nickreynke/python-gedcom.svg" alt="GitHub release"></a>
<a href="https://travis-ci.org/nickreynke/python-gedcom" target="_blank"><img src="https://travis-ci.org/nickreynke/python-gedcom.svg?branch=master" alt="Build Status"></a>
<a href="https://github.com/joeyaurel/python-gedcom/releases" target="_blank"><img src="https://img.shields.io/github/release/joeyaurel/python-gedcom.svg" alt="GitHub release"></a>
<a href="https://travis-ci.org/joeyaurel/python-gedcom" target="_blank"><img src="https://travis-ci.org/joeyaurel/python-gedcom.svg?branch=master" alt="Build Status"></a>
<img src="https://img.shields.io/badge/GEDCOM%20format%20version-5.5-yellowgreen.svg" alt="GEDCOM format version 5.5">
<img src="https://img.shields.io/badge/Python%20versions-3.5%20to%203.8-yellowgreen.svg" alt="Python versions 3.5 to 3.8">
</p>
Expand All @@ -21,19 +21,19 @@

## Documentation

Documentation can be found here: https://nickreynke.github.io/python-gedcom/gedcom/index.html
Documentation can be found here: https://joeyaurel.github.io/python-gedcom/gedcom/index.html

## Changelog

For the latest changes please have a look at the [`CHANGELOG.md`](CHANGELOG.md) file.

The current development process can be tracked in the [develop branch](https://github.com/nickreynke/python-gedcom/tree/develop).
The current development process can be tracked in the [develop branch](https://github.com/joeyaurel/python-gedcom/tree/develop).

## Common problems

* When you name your script `gedcom.py`, and import the `gedcom` module from this package, running your script won't
work because Python will try to resolve imports like `gedcom.element.individual` from within your `gedcom.py` but
not from within the module from this package. Rename your file in this case. ([#26](https://github.com/nickreynke/python-gedcom/issues/26))
not from within the module from this package. Rename your file in this case. ([#26](https://github.com/joeyaurel/python-gedcom/issues/26))

## Local development

Expand Down Expand Up @@ -75,14 +75,12 @@ Daniel Zappala at Brigham Young University (Copyright (C) 2005) which
was licensed under the GPL v2 and then continued by
[Mad Price Ball](https://github.com/madprime) in 2012.

The project was taken over by [Nicklas Reincke](https://github.com/nickreynke) in 2018.
Together with [Damon Brodie](https://github.com/nomadyow) a lot of changes were made and the parser was optimized.

## License

Licensed under the [GNU General Public License v2](http://www.gnu.org/licenses/gpl-2.0.html)

**Python GEDCOM Parser**
<br>Copyright (C) 2024 Joey Aurel (hi at joeyaurel.dev)
<br>Copyright (C) 2018 Damon Brodie (damon.brodie at gmail.com)
<br>Copyright (C) 2018-2019 Nicklas Reincke (contact at reynke.com)
<br>Copyright (C) 2016 Andreas Oberritter
Expand Down
Empty file added docs/.nojekyll
Empty file.
1 change: 0 additions & 1 deletion docs/CNAME

This file was deleted.

62 changes: 51 additions & 11 deletions gedcom/element/individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def is_private(self):
for child in self.get_child_elements():
if child.get_tag() == gedcom.tags.GEDCOM_TAG_PRIVATE:
private = child.get_value()
if private == 'Y':
if private == "Y":
return True

return False
Expand All @@ -93,7 +93,7 @@ def get_name(self):
# Some GEDCOM files don't use child tags but instead
# place the name in the value of the NAME tag.
if child.get_value() != "":
name = child.get_value().split('/')
name = child.get_value().split("/")

if len(name) > 0:
given_name = name[0].strip()
Expand All @@ -119,7 +119,11 @@ def get_name(self):
return given_name, surname

def get_all_names(self):
return [a.get_value() for a in self.get_child_elements() if a.get_tag() == gedcom.tags.GEDCOM_TAG_NAME]
return [
a.get_value()
for a in self.get_child_elements()
if a.get_tag() == gedcom.tags.GEDCOM_TAG_NAME
]

def surname_match(self, surname_to_match):
"""Matches a string with the surname of an individual
Expand Down Expand Up @@ -158,6 +162,17 @@ def get_gender(self):

return gender

def get_sosadaboville(self):
"""Returns the sosa daboville of a person in string format
:rtype: str
"""
# L'ajout du _SOSADABOVILLE est propre au logiciel Ancestris
sosadaboville = ""
for child in self.get_child_elements():
if child.get_tag() == "_SOSADABOVILLE":
sosadaboville = child.get_value()
return sosadaboville

def get_birth_data(self):
"""Returns the birth data of a person formatted as a tuple: (`str` date, `str` place, `list` sources)
:rtype: tuple
Expand Down Expand Up @@ -289,8 +304,8 @@ def get_census_data(self):
for child in self.get_child_elements():
if child.get_tag() == gedcom.tags.GEDCOM_TAG_CENSUS:

date = ''
place = ''
date = ""
place = ""
sources = []

for childOfChild in child.get_child_elements():
Expand Down Expand Up @@ -334,6 +349,31 @@ def get_occupation(self):

return occupation

def get_occupations(self):
"""Returns a list of occupation of a person individual formatted as tuples: (`str` date, `str´ place, `str` occu)
:rtype: list of tuple
"""
occupations = []

for child in self.get_child_elements():
if child.get_tag() == gedcom.tags.GEDCOM_TAG_OCCUPATION:

date = ""
place = ""
occupation = child.get_value()

for childOfChild in child.get_child_elements():

if childOfChild.get_tag() == gedcom.tags.GEDCOM_TAG_DATE:
date = childOfChild.get_value()

if childOfChild.get_tag() == gedcom.tags.GEDCOM_TAG_PLACE:
place = childOfChild.get_value()

occupations.append((date, place, occupation))

return occupations

def birth_year_match(self, year):
"""Returns `True` if the given year matches the birth year of this person
:type year: int
Expand Down Expand Up @@ -396,15 +436,15 @@ def criteria_match(self, criteria):

# Check if criteria is a valid criteria and can be split by `:` and `=` characters
try:
for criterion in criteria.split(':'):
criterion.split('=')
for criterion in criteria.split(":"):
criterion.split("=")
except ValueError:
return False

match = True

for criterion in criteria.split(':'):
key, value = criterion.split('=')
for criterion in criteria.split(":"):
key, value = criterion.split("=")

if key == "surname" and not self.surname_match(value):
match = False
Expand All @@ -422,7 +462,7 @@ def criteria_match(self, criteria):
elif key == "birth_range":

try:
from_year, to_year = value.split('-')
from_year, to_year = value.split("-")
from_year = int(from_year)
to_year = int(to_year)
if not self.birth_range_match(from_year, to_year):
Expand All @@ -442,7 +482,7 @@ def criteria_match(self, criteria):
elif key == "death_range":

try:
from_year, to_year = value.split('-')
from_year, to_year = value.split("-")
from_year = int(from_year)
to_year = int(to_year)
if not self.death_range_match(from_year, to_year):
Expand Down
22 changes: 22 additions & 0 deletions gedcom/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,28 @@ def __build_list(self, element, element_list):
self.__build_list(child, element_list)

# Methods for analyzing individuals and relationships between individuals
def get_marriage(self, family:FamilyElement):
"""Returns a marriage of a family formatted as a tuple (`str` date, `str` place)
:type family: FamilyElement
:rtype: tuple
"""
if not isinstance(family, FamilyElement):
raise NotAnActualFamilyError(
"Operation only valid for element with %s tag." % gedcom.tags.GEDCOM_TAG_FAMILY
)
# Get and analyze family.
for family_data in family.get_child_elements():
if family_data.get_tag() == gedcom.tags.GEDCOM_TAG_MARRIAGE:
date = ''
place = ''
for marriage_data in family_data.get_child_elements():
if marriage_data.get_tag() == gedcom.tags.GEDCOM_TAG_DATE:
date = marriage_data.get_value()
if marriage_data.get_tag() == gedcom.tags.GEDCOM_TAG_PLACE:
place = marriage_data.get_value()
return ((date,place))
return None


def get_marriages(self, individual):
"""Returns a list of marriages of an individual formatted as a tuple (`str` date, `str` place)
Expand Down