Skip to content

Commit

Permalink
Added the -X option to create a CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelhorne committed Aug 14, 2024
1 parent 0183d15 commit a733c15
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 21 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ The options are:
-L: include ged2site hyperlinks with -H
-m: month for -H calendar
-M: produce a map of a place (currently only Kent is supported) as
an animated gif of births and migration pattern into $surname.gif
an animated gif of births and migration pattern into $surname.gif or all.gif
-O: print a list of occupations, useful for finding typos and inconsistencies
-p: print the biography of the given person
-P: print a list of places, useful for finding typos of inconsistencies
Expand All @@ -140,6 +140,7 @@ The options are:
-w: print warning about inconsistent data - a sort of lint for Gedcom files
-W: don't colorize warning output
-x: prints a list of towns in a format suitable to import into a google map
-X: prints a CSV of information
-y: year for -H calendar, or -T to give a list of places for a specific year

## Running on Windows
Expand Down
65 changes: 45 additions & 20 deletions gedcom
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# all BMD, baptism and burials
# TODO: look at census records to note the different places that a person's children
# were born and note if the residences of the person don't include those places
# TODO: add an option for -Adw to create output as a CSV
# TODO: finish the -M option. Note that UK is:
# https://static-maps.yandex.ru/1.x/?lang=en_US&ll=-2.51,54.20&z=5&l=map&size=650,450
# Put the year on to the map as text
Expand Down Expand Up @@ -192,8 +191,8 @@ use Array::Iterator::BiDirectional;
sub get_location($);

my %opts;
getopts('aAbB:cCdDe:fFGgh:Hi:m:M:lLOp:PrsStwWxvy:', \%opts);
die "Usage: $0 [ -a ] [ -A ] [ -b ] [ -B book.pdf ] [ -c ] [ -C ] [ -d ] [ -D ] [ -f ] [ -F ] [ -G ] [ -h home-person-name ] [ -H [ -L [ -e ] ] [ -i ics_file ] [ -M place ] [ -m month ] [ -y year ] ] [ -l ] [ -p person-to-print ] [ -P ] [ -r ] [ -s ] [ -S ] [ -t ] [ -w [ -W ] [ -g | -x ]] filename [ filename2 ]" unless($ARGV[0]);
getopts('aAbB:cCdDe:fFGgh:Hi:m:M:lLOp:PrsStwWxXvy:', \%opts);
die "Usage: $0 [ -a ] [ -A ] [ -b ] [ -B book.pdf ] [ -c ] [ -C ] [ -d ] [ -D ] [ -f ] [ -F ] [ -G ] [ -h home-person-name ] [ -H [ -L [ -e ] ] [ -i ics_file ] [ -M place ] [ -m month ] [ -y year ] ] [ -l ] [ -p person-to-print ] [ -P ] [ -r ] [ -s ] [ -S ] [ -t ] [ -w [ -W ] [ -g | -x ]] [ -X ] filename [ filename2 ]" unless($ARGV[0]);

print "Starting\n" if($opts{'v'});

Expand Down Expand Up @@ -766,6 +765,9 @@ if($opts{'A'} && $opts{'G'}) {
if($opts{'S'} && $opts{'B'}) {
die '-S doesn\'t make sense with the -B option';
}
if($opts{'X'} && $opts{'B'}) {
die '-X doesn\'t make sense with the -B option';
}

if($opts{'B'}) {
$pdf = PDF::API2->new(-file => $opts{'B'});
Expand Down Expand Up @@ -1107,6 +1109,12 @@ if($opts{'H'}) {

if($opts{'B'} || $opts{i} || ((!$opts{'x'}) && (!$opts{'A'}) && !$opts{'g'} && !$opts{'M'})) {
$pr = String::ProgressBar->new(max => scalar(@everyone), length => 60);
} elsif($opts{'X'}) {
if($me) {
print '"xref","relationship","given names","surname","date of birth","date of death"', "\n";
} else {
print '"xref","given names","surname","date of birth","date of death"', "\n";
}
}

if($opts{'G'} && $dot && $me) {
Expand Down Expand Up @@ -1875,11 +1883,12 @@ sub print_person
next if(abs($yod - $year) > 2); # Died more than two years before the possible match was born
die 'TODO: Potential match: ', $person->as_string($string_args), '/', $possible->as_string($string_args);
}
} elsif(my $relationship = $possible->relationship($person)) {
} elsif(my $relationship = $person->relationship($possible)) {
next if($relationship eq 'father');
next if($relationship eq 'mother');
next if($relationship eq 'son');
next if($relationship eq 'daughter');
die 'TODO: Potential match: ', $person->as_string($string_args), '/', $possible->as_string($string_args);
} elsif($given ne '?') {
die 'TODO: Potential match: ', $person->as_string($string_args), '/', $possible->as_string($string_args);
}
Expand Down Expand Up @@ -2121,6 +2130,29 @@ sub print_person
push @{$all_occupations{$occupation}}, $person;
}

return;
} elsif($opts{'X'}) {
print '"', $person->xref(), '",';
if($me && ($person->xref() ne $me->xref())) {
print '"', $me->relationship($person), '",';
}
print '"', given_names($person), '","', ucfirst(lc($person->surname())), '",';
if($dateofbirth) {
if($dateofbirth =~ /\D/) {
print "\"$dateofbirth\"";
} else {
print $dateofbirth;
}
}
print ',';
if($dateofdeath) {
if($dateofdeath =~ /\D/) {
print "\"$dateofdeath\"";
} else {
print $dateofdeath;
}
}
print "\n";
return;
} else {
print $person->as_string($args), "\n";
Expand Down Expand Up @@ -7540,7 +7572,6 @@ sub print_person
$bio->append(conjunction(map { $_->as_string() } @phrases));
}
}
print $bio->rtrim()->as_string();
if($opts{'w'} && (my $dbpedia = dbpedia({ person => $person, birth_dt => $birth_dt, yob => $yob, yod => $yod, birth_country => $birth_country }))) {
# FIXME: add citation
if($opts{'B'}) {
Expand Down Expand Up @@ -8543,7 +8574,7 @@ sub Gedcom::Individual::relationship_up
return unless scalar(@myancestors);
@ancestors = @myancestors;
} else {
@ancestors = $self->ancestors();
@myancestors = $self->ancestors();
}

my $sex = get_value({ person => $other, value => 'sex' });
Expand Down Expand Up @@ -9219,7 +9250,7 @@ sub Gedcom::Individual::relationship_up
}
}
if(!defined($rc)) {
# die $other->as_string(), ": $steps1, $steps2";
die $other->as_string({ nee => 1, middle_names => 1, include_years => 1 }), ": $steps1, $steps2";
complain({ person => $other, warning => "TODO: $steps1, $steps2" });
}
return $rc;
Expand Down Expand Up @@ -10753,21 +10784,13 @@ sub date_parser_cached
# Try hard to convert a Gedcom date to a DateTime object.
sub date_to_datetime
{
my %params;

if(ref($_[0]) eq 'HASH') {
%params = %{$_[0]};
} elsif(scalar(@_) % 2 == 0) {
%params = @_;
} else {
$params{'date'} = shift;
}
my $params = get_params('date', @_);

if(my $date = $params{'date'}) {
if(my $date = $params->{'date'}) {
# if($date !~ /^(bef|abt|aft).?\s/i) {
if(($date !~ /^(bef|abt|aft)/i) && ($date !~ /\sor\s/)) {
$params{'quiet'} = 1 if(!$opts{'w'});
return $dfg->parse_datetime(%params);
$params->{'quiet'} = 1 if(!$opts{'w'});
return $dfg->parse_datetime(%${params});
}
}
return; # undef
Expand Down Expand Up @@ -13921,6 +13944,7 @@ your::Ihr
brother::bror
child::barn
father::far
mother::mor
sister::søster
@@ Latin
and::et
Expand All @@ -13931,7 +13955,8 @@ mother::mater
sister::soror
wife::uxor
@@ Norwegian
brother::far
father::far
mother::mor
sister::søster
@@ Spanish
aunt::tia
Expand Down

0 comments on commit a733c15

Please sign in to comment.