From a733c15cd6ff46199e99d13ecf5a644b0ddfffc0 Mon Sep 17 00:00:00 2001 From: Nigel Horne Date: Wed, 14 Aug 2024 14:04:30 -0400 Subject: [PATCH] Added the -X option to create a CSV --- README.md | 3 ++- gedcom | 65 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 0db147a..2ea21d2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/gedcom b/gedcom index e03f8f1..a7d2d57 100755 --- a/gedcom +++ b/gedcom @@ -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 @@ -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'}); @@ -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'}); @@ -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) { @@ -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); } @@ -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"; @@ -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'}) { @@ -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' }); @@ -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; @@ -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 @@ -13921,6 +13944,7 @@ your::Ihr brother::bror child::barn father::far +mother::mor sister::søster @@ Latin and::et @@ -13931,7 +13955,8 @@ mother::mater sister::soror wife::uxor @@ Norwegian -brother::far +father::far +mother::mor sister::søster @@ Spanish aunt::tia