839B; Perl | Statements 22 | SLOC 26
1
#!/usr/bin/env perl
2
3
use warnings;
4
use strict;
5
use autodie qw(:all);
6
7
use Geo::Coder::Free;
8
9
die "Usage: $0 gedcom-file" unless($ARGV[0]);
10
die 'Set OPENADDR_HOME to enable testing' unless($ENV{'OPENADDR_HOME'});
11
12
# my $g = Geo::Coder::Free::OpenAddresses->new(openaddr => $ENV{'OPENADDR_HOME'});
13
my $g = Geo::Coder::Free->new(openaddr => $ENV{'OPENADDR_HOME'});
14
15 1
open(my $fin, '-|', "./gedcom -T \"$ARGV[0]\"") or die;
16
17
while(my $line = <$fin>) {
18
	next if($line =~ /\d%/);
19
20
	$line =~ s/:\s.+$//;
21
	$line =~ s/[\r\n]//;
22
23
	run($line);
24
}
25
26
sub run {
27
	my $l = shift;
28
29
	# return unless($l =~ /(Canada|US|USA|United States)$/i);
30
31
	eval {
32
		if(!defined($g->geocode($l))) {
33
			print "$l failed\n";
34
		}
35
		# if(my $rc = $g->geocode($l)) {
36
			# print "$l: ", $rc->{'latitude'}, '/', $rc->{'longitude'}, "\n";
37
		# }
38
	};
39
	if($@) {
40
		print "$l: $@";
41
	}
42
}