fastgedcom.helpers
Utilitary functions to sort, format, or extract information.
Module Contents
Classes
Date modifiers allowed by the Gedcom specifications. |
Functions
|
/!DEPRECATED /!use the method |
|
/!DEPRECATED /!use the method |
|
Format the payload of NAME lines. |
|
Split the payload of NAME lines into the given name and the surname parts. |
|
Return the modifier used by DATE line payloads. |
|
Removes useless 0 prefixing numbers. |
|
Format the payload of DATE lines. |
|
Format the payload of DATE lines. |
Format the payload of DATE lines. |
|
|
Convert the payload of DATE lines to datetime object. |
|
Convert the payload of DATE lines to datetime objects. |
|
Parse the payload of TIME lines. |
|
Convert DATE lines to datetime object using the payload and the TIME sub-line. |
- fastgedcom.helpers.get_all_sub_lines(line: fastgedcom.base.TrueLine) Iterator[fastgedcom.base.TrueLine] [source]
/!DEPRECATED /!use the method
Line.get_all_sub_lines()
instead.Recursively iterate on
TrueLine
of higher level. All lines under the given line are returned. The order is preserved as in the gedcom file, sub-lines come before siblings lines.
- fastgedcom.helpers.get_source(line: fastgedcom.base.TrueLine | fastgedcom.base.FakeLine) str [source]
/!DEPRECATED /!use the method
Line.get_source()
instead.Return the gedcom text equivalent for the line and its sub-lines.
- fastgedcom.helpers.format_name(name: str) str [source]
Format the payload of NAME lines. Remove the backslash around the surname.
- fastgedcom.helpers.extract_name_parts(name: str) tuple[str, str] [source]
Split the payload of NAME lines into the given name and the surname parts. The surname is the part of the payload surrounded by ‘/’.
- class fastgedcom.helpers.DateType(*args, **kwds)[source]
Bases:
enum.Enum
Date modifiers allowed by the Gedcom specifications. They can appear in payload of DATE lines.
- fastgedcom.helpers.get_date_type(date: str) DateType | None [source]
Return the modifier used by DATE line payloads. If no modifier is recognized, return None. Ignore
BC
andBCE
and return None, because these modifiers can be combined with the others.
- fastgedcom.helpers.remove_trailing_zeros(date: str) str [source]
Removes useless 0 prefixing numbers.
- fastgedcom.helpers.format_date(date: str) str [source]
Format the payload of DATE lines. Return a short string representation of the date by replacing gedcom keywords by symbols.
Replacements:
BC
is replaced by -.BCE
is replaced by -.ABT
is replaced by ~.EST
is replaced by ~.CAL
is replaced by ~.BEF
is replaced by <.AFT
is replaced by >.FROM
is removed.TO
is removed.BET_AND
is replaced by –.FROM_TO
is replaced by –.
- fastgedcom.helpers.extract_year(date: str) str [source]
Format the payload of DATE lines.
Keep the context of the date, i.e. replacements produced by
format_date()
. To extract the year but not the context, useextract_int_year()
.Remove the day and the month if present. The parameter is the DATE payload or the formatted date string.
- fastgedcom.helpers.extract_int_year(date: str) float | None [source]
- fastgedcom.helpers.extract_int_year(date: str, default: float) float
Format the payload of DATE lines. Return the year of the date as an integer. On failure, return the default.
A
BCE
date returns a negative number. ForBET_AND
andFROM_TO
date types, this function returns the median number of the range, hence the float type.
- fastgedcom.helpers.to_datetime(date: str, default: datetime.datetime | None = None) datetime.datetime [source]
Convert the payload of DATE lines to datetime object.
If default is provided, return default on failure. Otherwise, raise ValueError on failure.
If no day or month is specified, the first day and month are used.
The returned date is more precise than
extract_int_year()
, but works less often. Infact, this method only works for positive dates (i.e. notBC
) andABT
,CAL
,EST
date types. ForBET_AND
orTO_FROM
date types, use theto_datetime_range()
function. TheBEF
andAFT
date types are not supported.
- fastgedcom.helpers.to_datetime_range(date: str, default: datetime.datetime | None = None) tuple[datetime.datetime, datetime.datetime] [source]
Convert the payload of DATE lines to datetime objects.
If default is provided, return default on failure. Otherwise, raise ValueError on failure.
A case of failure is if the date types is not
BET_AND
, orFROM_TO
.Call
to_datetime()
on the first and second date.
- fastgedcom.helpers.add_time(date: datetime.datetime, time_: str) datetime.datetime [source]
Parse the payload of TIME lines. If the time is parsed, return the datetime with its time set. Otherwise, return the datetime as it was.
Note: datetime is immutable, thus the presence of a returned value.
- fastgedcom.helpers.line_to_datetime(date: fastgedcom.base.TrueLine | fastgedcom.base.FakeLine, default: datetime.datetime | None = None) datetime.datetime [source]
Convert DATE lines to datetime object using the payload and the TIME sub-line.
If default is provided, return default on date parsing failure. Otherwise, raise ValueError on failure.