/
ged2site
executable file
·8070 lines (7512 loc) · 253 KB
/
ged2site
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
# Author Nigel Horne: njh@bandsman.co.uk
# Copyright (C) 2015-2019, Nigel Horne
# Usage is subject to licence terms.
# The licence terms of this software are as follows:
# Personal single user, single computer use: GPL2
# All other users (including Commercial, Charity, Educational, Government)
# must apply in writing for a licence for use from Nigel Horne at the
# above e-mail.
# TODO: Geo::Coder::GeocodeFarm, once github issue 1 has been fixed
# TODO: Investigate BGS
# TODO: Finish XML
# TODO: Can I use a kdTree to determine events or residences close by each other?
# TODO: note if a child was orphaned by both parents dying before they were 16
# TODO: add male and female average lifespan to the facts
# TODO: finish -x option to create a blog of differences over time of
# changes to the tree
# -d: Download copies of objects rather than link to them, useful if the
# objects are on pay sites such as FMP
#
# For the Simile Timeline format see
# http://www.simile-widgets.org/wiki/Timeline_EventSources
# For visjs see
# http://visjs.org/docs/timeline/
BEGIN {
eval 'use Geo::Coder::List';
if($@) {
system('cpan -i Gedcom Genealogy::Gedcom::Date Date::Parse Geo::Coder::List Geo::Coder::Free IPC::System::Simple Geo::Coder::Ovi String::Compare');
system('cpan -i Geo::Coder::RandMcnally Geo::Coder::US::Census Geo::Coder::OSM Geo::Coder::XYZ Geo::Coder::CA Geo::Coder::Postcodes');
system('cpan -i Geo::Coder::GooglePlaces Geo::Coder::Bing Geo::GeoNames F/FR/FRIFFIN/Geo-Coder-PlaceFinder-0.1.tar.gz');
system('cpan -i Lingua::EN::NameCase Lingua::EN::Numbers::Ordinate Lingua::EN::ABC Lingua::EN::Inflect DateTime DateTime::Format::Natural');
system('cpan -i DateTime::Format::Genealogy URI::Find::Schemeless Sort::Key::DateTime Text::Names::GB Data::Fetch HTTP::Cache::Transparent HTML::Table Geo::Coder::DataScienceToolkit LWP::UserAgent::Cached XML::Dumper XML::Twig CHI Class::Simple');
}
}
use strict;
use warnings;
use autodie qw(:all);
# use warnings::unused;
# BEGIN {
# *CORE::GLOBAL::die = \&main::die;
# }
no lib '.';
use CHI;
use Class::Simple;
use Gedcom;
use Getopt::Std;
use Lingua::EN::NameCase;
use Lingua::EN::NameParse;
use Lingua::EN::Numbers::Ordinate;
use Lingua::EN::ABC;
use Lingua::EN::Inflect;
# use Lingua::EN::AddressParse;
use Geo::StreetAddress::US;
use Locale::US;
use DateTime;
use DateTime::Format::Natural;
use DateTime::Format::Genealogy;
use Genealogy::Gedcom::Date;
use DateTime::Duration;
use Geo::Coder::DataScienceToolkit;
use Geo::Coder::List 0.15;
use Geo::Coder::Free 0.10; # 0.11 really
use Geo::Coder::Free::OpenAddresses;
use Geo::Coder::Free::Local;
use Geo::Coder::Postcodes 0.02;
use Geo::Coder::OSM;
use Geo::Coder::XYZ;
use Geo::Coder::GooglePlaces;
use Geo::Coder::Bing;
use Geo::Coder::PlaceFinder;
use Geo::GeoNames;
use Geo::Coder::Google;
use Geo::Coder::Bing;
use Geo::Coder::CA;
use Geo::Coder::Ovi;
use Geo::Coder::RandMcnally;
use Geo::Coder::US::Census;
use Geo::Parser::Text;
use GIS::Distance;
use HTML::GoogleMaps::V3 0.13;
use Term::ANSIColor;
use HTML::Entities;
use HTTP::Cache::Transparent;
use File::Basename;
use File::Spec;
use File::Temp;
use Image::Info;
use URI;
use URI::Find::Schemeless;
use LWP::Simple;
use LWP::UserAgent::Throttled;
use Sort::Key::DateTime;
use String::ProgressBar;
use Text::Names;
use Text::Names::GB;
use MIME::Base64;
use Text::Names;
use Memoize;
use File::Copy;
use Data::Fetch;
use Config::Auto;
use Locale::Object::Country;
use List::Util;
use POSIX;
use String::Compare;
use JSON;
use File::Print::Many;
use XML::Dumper;
use XML::Twig;
my %opts;
getopts('cdfFG:g:h:J:lL:mwvx:', \%opts);
die "Usage: $0 [ -c ] [ -d ] [ -F ] [ -f ] [ -g google-search-verification ] [ -h home-person-name ] [ -l ] [ -L max_records ] [ -m [-G Google-Maps-GeoLocation-key ] [ -J Google-Maps-JavaScript-key ] ] [ -w ] [ -x current_people.xml ] filename [ filename2 ]\n" unless($ARGV[0]);
use constant MAX_INDEX => 0; # Debugging, set this to the number of records to print.
# Set to 0 to run on the entire database
my $me;
my @myancestors;
my @mydescendents;
my %warned;
my %printed;
my %places;
my $surnames;
my %censuses;
my %twins;
my %military;
my %images;
my %all_locations;
my %all_events; # Maps events to people
my %all_dates; # Maps dates to the hashref from Genealogy::Gedcom::Date
my %name_date; # Maps first names to quarter century
my %changes; # If the -x option is given, tracks changes between the previous run and this run
my $facts;
my $pi = atan2(1,1) * 4;
# FIXME: Should be in a configuration file
# Will be removed when new G:C:Free is published
my %known_locations = (
'Newport Pagnell, Buckinghamshire, England' => {
'latitude' => 52.08675,
'longitude' => -0.72270
}
);
# Help OSM to match
my %location_mappings = (
'Coventry, Warwickshire, England' => 'Coventry, England',
'Minster, Sheppey, Kent' => 'Minster, Swale, Kent',
'Bromley, Kent, Endland' => 'Bromley, London, England',
'Croydon, Surrey, Endland' => 'Croydon, London, England',
'Thornton Heath, Surrey, Endland' => 'Thornton Heath, London, England',
'Edinburgh, Midlothian, Scotland' => 'Edinburgh, Scotland',
);
my $nameparser = Lingua::EN::NameParse->new(extended_titles => 1);
my $ged = Gedcom->new(gedcom_file => $ARGV[0], read_only => 1);
my $ged2;
if($ARGV[1]) {
$ged2 = Gedcom->new(gedcom_file => $ARGV[1], read_only => 1);
}
my $dfn = DateTime::Format::Natural->new();
my $dfg = DateTime::Format::Genealogy->new();
my $date_parser = Genealogy::Gedcom::Date->new();
my $oneday = DateTime::Duration->new(days => 1);
my $tenmonths = DateTime::Duration->new(months => 10);
my $sixteenyears = DateTime::Duration->new(years => 16);
my $fortyyears = DateTime::Duration->new(years => 40);
my $fetcher;
my $year_1000 = DateTime->new(year => 1000, month => 1, day => 1);
my $config;
eval { $config = Config::Auto::parse() };
my %gp_args = (apiver => 3);
my $geolocation_key;
if($opts{'G'}) {
$geolocation_key = $opts{'G'};
} elsif($ENV{'GMAP_KEY'}) { # Compatibility with various CPAN modules
$geolocation_key = $ENV{'GMAP_KEY'};
} elsif($config && $config->{'google_maps_geolocation_key'}) {
$geolocation_key = $config->{'google_maps_gelocation_key'};
}
$gp_args{'key'} = $geolocation_key;
$gp_args{'api_key'} = $geolocation_key;
my $javascript_key;
if($opts{'J'}) {
$javascript_key = $opts{'J'};
} elsif($config && $config->{'google_maps_javascript_key'}) {
$javascript_key = $config->{'google_maps_javascript_key'};
}
my $geocoder;
my $textgeocoder;
my $freegeocoder;
if($opts{'m'} || $opts{'w'}) {
my $l = $ENV{'LANG'};
if(defined($l) && ($l =~ /^([a-z]{2})/i)) {
$gp_args{'language'} = lc($1);
}
# my $geocoder = Geo::Coder::List->new(cache => CHI->new(driver => 'Memcached', servers => [ '192.168.1.15:11211', '127.0.0.1:11211' ]));
my $cachedir;
if(my $e = $ENV{'CACHEDIR'}) {
$cachedir = File::Spec->catfile($e, basename($0));
} else {
$cachedir = File::Spec->catfile(File::Spec->tmpdir(), 'cache', basename($0));
}
$geocoder = Geo::Coder::List->new(cache => CHI->new(driver => 'File', root_dir => $cachedir));
if(my $oa = $ENV{'OPENADDR_HOME'}) {
$freegeocoder = Geo::Coder::Free->new(openaddr => $oa);
# $geocoder->push({ regex => qr/,[\w\s]+,[\w\s]+$/, geocoder => $freegeocoder });
# $geocoder->push({ regex => qr/,\s*(USA|US|United States|Canada|Australia)+$/, geocoder => Geo::Coder::Free::OpenAddresses->new(openaddr => $oa) })
# ->push({ regex => qr/^[\w\s\-]+?,[\w\s]+,[\w\s]+?$/, geocoder => Geo::Coder::Free->new() });
# US, Canada and Australia are full
# Counties and towns in the UK are full
$geocoder->push({ regex => qr/,\s*(USA|US|United States|Canada|Australia)\s*$/, geocoder => $freegeocoder })
->push({ regex => qr/^([\w\s]+,)?\s*[\w\s]+,\s*[\w\s]+\s*$/, geocoder => $freegeocoder });
} else {
$freegeocoder = Geo::Coder::Free->new();
$geocoder->push({ regex => qr/^[\w\s\-]+?,[\w\s]+,[\w\s]+?$/, geocoder => $freegeocoder })
# E.g. 'Nebraska, USA'
->push({ regex => qr/^[\w\s]+,\s*(UK|England|Canada|USA|US|United States)$/i, geocoder => $freegeocoder });
}
$geocoder->push({ regex => qr/^[\w\s]+,\s*[\w\s],\s*(UK|England|Wales|Scotland)$/i, geocoder => $freegeocoder })
->push(Geo::Coder::Free::Local->new());
if(my $username = $ENV{'GEONAMES_USER'}) {
$geocoder->push(Geo::GeoNames->new(username => $username));
}
if($geolocation_key) {
# DST isn't that good for the UK
# $geocoder->push({ regex => qr/(UK|United Kingdom|England|USA|US|United States|Wales)$/i, geocoder => Geo::Coder::DataScienceToolkit->new() })
$geocoder->push({ regex => qr/(USA|US|United States)$/i, geocoder => Geo::Coder::DataScienceToolkit->new() })
->push({ regex => qr/^\d.+?,.+?,\s*(USA|US|United States)$/i, geocoder => Geo::Coder::US::Census->new() })
->push({ limit => 100, regex => qr/(Canada|USA|US|United States)$/i, geocoder => Geo::Coder::CA->new() })
->push({ regex => qr/(USA|US|United States)$/i, geocoder => Geo::Coder::RandMcnally->new() })
->push(Geo::Coder::OSM->new())
->push({ regex => qr/^[\w\s-]+,\s*[\w\s]+,\s*(UK|United Kingdom|England|Wales)$/i, geocoder => Geo::Coder::Postcodes->new() })
->push(Geo::Coder::Ovi->new())
->push({ limit => 100, geocoder => Geo::Coder::GooglePlaces->new(%gp_args) })
->push({ limit => 200, geocoder => Geo::Coder::XYZ->new()})
->push(Geo::Coder::Google->new());
} else {
# DST isn't that good for the UK
# $geocoder->push({ regex => qr/(UK|United Kingdom|England|USA|US|United States|Wales)$/i, geocoder => Geo::Coder::DataScienceToolkit->new() })
$geocoder->push({ regex => qr/(USA|US|United States)$/i, geocoder => Geo::Coder::DataScienceToolkit->new() })
->push({ regex => qr/^\d.+?,.+?,\s*(USA|US|United States)$/i, geocoder => Geo::Coder::US::Census->new() })
->push({ limit => 100, regex => qr/(Canada|USA|US|United States)$/i, geocoder => Geo::Coder::CA->new() })
->push({ regex => qr/(USA|US|United States)$/i, geocoder => Geo::Coder::RandMcnally->new() })
->push({ regex => qr/^[\w\s-]+,\s*[\w\s]+,\s*(UK|United Kingdom|England|Wales)$/i, geocoder => Geo::Coder::Postcodes->new() })
->push(Geo::Coder::OSM->new())
# ->push({ limit => 200, geocoder => Geo::Coder::XYZ->new()})
->push(Geo::Coder::Ovi->new());
# ->push(Geo::Coder::Google->new())
# ->push(Geo::Coder::GooglePlaces->new());
}
if(my $key = $ENV{BMAP_KEY}) {
$geocoder->push(Geo::Coder::Bing->new(key => $key));
}
my $ua = LWP::UserAgent::Throttled->new(agent => basename($0), keep_alive => 1);
$ua->env_proxy(1);
# TODO: throttle other geocoders
$ua->throttle({
'nominatim.openstreetmap.org' => 1,
'geocode.xyz' => 2,
'geocoder.ca' => 1,
'api.postcodes.io' => 1,
'where.desktop.mos.svc.ovi.com' => 1,
'geocoding.geo.census.gov' => 1,
'a2ageo.rmservers.com' => 1,
'dev.virtualearth.net' => 1, # Bing
'api.geonames.org' => 1,
'yboss.yahooapis.com' => 1, # Geo::Coder::PlaceFinder
});
# G::C::GooglePlaces
$ua->throttle({ 'maps.googleapis.com' => 0.1 }) unless($geolocation_key);
$ua->ssl_opts(verify_hostname => 0); # prevent "Can't connect to geocode.xyz:443 (certificate verify failed)"
$geocoder->ua($ua);
# Geo::Coder::PlaceFinder doesn't support the ua() method
if((my $ckey = $ENV{'YAHOO_CONSUMER'}) && (my $skey = $ENV{'YAHOO_SECRET'})) {
$geocoder->push(Geo::Coder::PlaceFinder->new(consumer_key => $ckey, secret_key => $skey, ua => $ua));
}
# $textgeocoder = Geo::Parser::Text->new('https://geocoder.ca');
$textgeocoder = Geo::Parser::Text->new('https://geocode.xyz');
}
# FIXME: Do this properly
my %censusmaps = (
'1841 England Census' => '1841 UK Census',
'1841 England, Wales & Scotland Census - Findmypast' => '1841 UK Census',
'1851 England Census' => '1851 UK Census',
'1851 Wales Census' => '1851 UK Census',
'1851 Census' => '1851 UK Census',
'1851 England, Wales & Scotland Census - Findmypast' => '1851 UK Census',
'1851 United Kingdom Census Sample' => '1851 UK Census',
'1861 England Census' => '1861 UK Census',
'1861 England, Wales & Scotland Census - Findmypast' => '1861 UK Census',
'1871 England Census' => '1871 UK Census',
'1871 England, Wales & Scotland Census - Findmypast' => '1871 UK Census',
'1871 Wales Census' => '1871 UK Census',
'1881 England Census' => '1881 UK Census',
'1881 England, Wales & Scotland Census - Findmypast' => '1881 UK Census',
'1881 Isle of Man Census' => '1881 Isle of Man Census',
'1881 Wales Census' => '1881 UK Census',
'1891 England Census' => '1891 UK Census',
'1891 England, Wales & Scotland Census - Findmypast' => '1891 UK Census',
'1891 Wales Census' => '1891 UK Census',
'1901 England Census' => '1901 UK Census',
'1901 Wales Census' => '1901 UK Census',
'1901 England, Wales & Scotland Census - Findmypast' => '1901 UK Census',
'1911 England Census' => '1911 UK Census',
'1911 England Census Summary Books' => '1911 UK Census',
'1911 Census for England & Wales - Findmypast' => '1911 UK Census',
'1911 Wales Census' => '1911 UK Census',
'1851 Census of Canada East, Canada West, New Brunswick, and Nova Scotia' => '1851 Canadian Census',
'1861 Census of Canada' => '1861 Canadian Census',
'1871 Census of Canada' => '1871 Canadian Census',
'Kent County, New Brunswick Census, 1871: Eight Subdistricts' => '1871 Canadian Census',
'1881 Census of Canada' => '1881 Canadian Census',
'1891 Census of Canada' => '1891 Canadian Census',
'Canada Census 1891 - Findmypast' => '1891 Canadian Census',
'1901 Census of Canada' => '1901 Canadian Census',
'Canada Census 1901 - Findmypast' => '1901 Canadian Census',
'1906 Canada Census of Manitoba, Saskatchewan, and Alberta' => '1906 Canadian Census',
'Canada Census 1911 - Findmypast' => '1911 Canadian Census',
'1911 Census of Canada' => '1911 Canadian Census',
'1916 Canada Census of Manitoba, Saskatchewan, and Alberta' => '1916 Canadian Census',
'1921 Census of Canada' => '1921 Canadian Census',
'1850 United States Federal Census' => '1850 US Census',
'US Census 1850 - Findmypast' => '1850 US Census',
'Us Census 1850 - Findmypast' => '1850 US Census', # Strange...
'New York, State Census, 1855' => '1855 New York Census',
'1860 United States Federal Census' => '1860 US Census',
'US Census 1860 - Findmypast' => '1860 US Census',
'Nebraska, State Census Collection, 1860-1885' => '1860 US Census',
'New York, State Census, 1865' => '1865 New York Census',
'US Census 1870 - Findmypast' => '1870 US Census',
'1870 United States Federal Census' => '1870 US Census',
'New York, State Census, 1875' => '1875 New York Census',
'1880 United States Federal Census' => '1880 US Census',
'US Census 1880 - Findmypast' => '1880 US Census',
'Us Census 1880 - Findmypast' => '1880 US Census',
'US Census 1900 - Findmypast' => '1900 US Census',
'1900 United States Federal Census' => '1900 US Census',
'New York, State Census, 1905' => '1905 New York Census',
'1910 United States Federal Census' => '1910 US Census',
'US Census 1910 - Findmypast' => '1910 US Census',
'1920 United States Federal Census' => '1920 US Census',
'US Census 1920 - Findmypast' => '1920 US Census',
'New York, State Census, 1925' => '1925 US State Censuses',
'South Dakota, State Census, 1925' => '1925 US State Censuses',
'US Census 1930 - Findmypast' => '1930 US Census',
'1930 United States Federal Census' => '1930 US Census',
'South Dakota, State Census, 1935' => '1935 US Census',
'US Census 1940 - Findmypast' => '1940 US Census',
'1940 United States Federal Census' => '1940 US Census',
);
# sub realdie
# {
# CORE::die (@_);
# }
# sub die {
# my @arg = shift;
#
# print STDERR "@arg\n" if($arg[0]);
#
# my $i = 0;
# while((my @call_details = (caller($i++)))) {
# print STDERR $call_details[1], ':', $call_details[2], ' in function ', $call_details[3], "\n";
# }
#
# realdie @arg;
# }
# $ged->validate();
my $home = $opts{h};
if((!defined($home)) && defined($config)) {
$home = $config->{'home'};
if(ref($home) eq 'ARRAY') {
$home = join(' ', @{$home});
}
}
if($home) {
$me = $ged->get_individual($home);
unless($me) {
die "$0: Can't find '$opts{h}' in $ARGV[0]";
}
}
my $dot;
my $jpegtran;
my $jpegoptim;
if($opts{'F'}) {
if(-x '/usr/bin/dot') {
$dot = '/usr/bin/dot';
} elsif(-x '/usr/local/bin/dot') {
$dot = '/usr/local/bin/dot';
} elsif(-x '/sw/bin/dot') {
$dot = '/sw/bin/dot';
}
if(!defined($dot)) {
complain(warning => 'Graphviz not found, no family trees');
} else {
require Image::Magick::Thumbnail;
Image::Magick::Thumbnail->import();
print "Using $dot\n" if($opts{'v'});
}
}
my @dirlist = ('static-site', 'dynamic-site/databases');
if($dot || $opts{'d'}) {
push @dirlist, 'static-site/img';
push @dirlist, 'dynamic-site/img';
push @dirlist, 'thumbs';
if(-x '/usr/bin/jpegtran') {
$jpegtran = '/usr/bin/jpegtran';
} elsif(-x '/usr/local/bin/jpegtran') {
$jpegtran = '/usr/local/bin/jpegtran';
} elsif(-x '/opt/local/bin/jpegtran') {
$jpegtran = '/opt/local/bin/jpegtran';
} elsif(-x '/sw/bin/jpegtran') {
$jpegtran = '/sw/bin/jpegtran';
}
if(-x '/usr/bin/jpegoptim') {
$jpegoptim = '/usr/bin/jpegoptim';
} elsif(-x '/usr/local/bin/jpegoptim') {
$jpegoptim = '/usr/local/bin/jpegoptim';
} elsif(-x '/sw/bin/jpegoptim') {
$jpegoptim = '/sw/bin/jpegoptim';
}
}
my $gedcal;
if(-x '/usr/bin/gedcom') {
$gedcal = '/usr/bin/gedcom';
} elsif(-x '/usr/local/bin/gedcom') {
$gedcal = '/usr/local/bin/gedcom';
} elsif(-x '../gedcom/gedcom') {
$gedcal = '../gedcom/gedcom';
}
if($gedcal) {
push @dirlist, 'static-site/calendar';
}
foreach my $dir(@dirlist) {
mkdir $dir if(!-d $dir);
}
my $browser;
my $cached_browser;
if($opts{'d'} || $opts{'m'}) {
$browser = LWP::UserAgent->new();
$browser->env_proxy(1);
my $cachedir;
if(my $e = $ENV{'CACHEDIR'}) {
$cachedir = File::Spec->catfile($e, 'http-cache-transparent');
} else {
$cachedir = File::Spec->catfile(File::Spec->tmpdir(), 'cache', 'http-cache-transparent');
}
if(!-d $cachedir) {
mkdir $cachedir || die "$cachedir: $!";
}
HTTP::Cache::Transparent::init({
BasePath => $cachedir,
Verbose => $opts{'v'} ? 1 : 0,
NoUpdate => 24 * 60 * 60,
});
}
my @everyone = $ged->individuals();
my $total = scalar(@everyone);
if($total == 0) {
die "$0: gedcom file is empty\n";
}
my $index = 0;
my $dtl = DateTime::Locale->load($ENV{'LANG'});
my $pr;
my $us;
if($opts{'w'}) {
require Locale::US;
Locale::US->import();
$us = Locale::US->new();
require LWP::UserAgent::Cached;
LWP::UserAgent::Cached->import();
my $cachedir;
if(my $e = $ENV{'CACHEDIR'}) {
$cachedir = File::Spec->catfile($e, 'lwp');
} else {
$cachedir = File::Spec->catfile(File::Spec->tmpdir(), 'cache', 'lwp');
}
if(!-d $cachedir) {
mkdir $cachedir || die "$cachedir: $!";
}
$cached_browser = LWP::UserAgent::Cached->new(cache_dir => $cachedir,
agent => basename($0),
keep_alive => 1
);
$cached_browser->env_proxy(1);
} else {
$pr = String::ProgressBar->new(max => $total, length => 60);
}
memoize('Gedcom::Individual::as_string');
memoize('stepsabove');
memoize('normalize_name');
memoize('date_to_datetime');
my $key = delete $opts{'g'}; # Ensure it's not stored in the XML file
my $current_people = delete $opts{'x'};
if($current_people) {
# Creating a changelog only works if the many of the options are the same
my $xml = XML::Twig->new();
$xml->parsefile($current_people);
my %prev_opts;
foreach my $key($xml->root()->first_child('opts')->first_child('hashref')->children()) {
if($key->name() eq 'item') {
$prev_opts{$key->{'att'}->{'key'}} = $key->first_child()->pcdata();
}
}
my $ok = 1;
for my $opt('c', 'd', 'h') {
if(defined($opts{$opt}) ne defined($prev_opts{$opt})) {
$ok = 0;
last;
}
if(defined($opts{$opt}) && ($opts{$opt} ne $prev_opts{$opt})) {
$ok = 0;
last;
}
}
if(!$ok) {
die "Runtime options aren't the same as given in $current_people\n";
}
$current_people = $xml;
}
open(my $xml, '>', 'dynamic-site/databases/people.xml');
print $xml "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n<table>\n";
my $string = XML::Dumper->new()->pl2xml(\%opts);
$string =~ s/perldata/opts/g;
print $xml "\t$string";
########
# print $xml "\n</table>\n"; exit;
########
open(my $csv, '>', 'dynamic-site/databases/people.csv');
print $csv "entry!title!home!alive!bio!father!mother!children!citations!notes!media!family_tree!map_head!map_body!dob!dod!profile_thumbnail!marriages!sex!birth_coords!death_coords!birth_country!death_country!warnings\n";
open(my $timeline_xml, '>', 'dynamic-site/timeline.xml');
print $timeline_xml "<?xml version=\"1.0\"?>\n",
"<data date-time-format=\"iso8601\">\n";
open(my $visjs, '>', 'dynamic-site/visjs.html');
print $visjs <<'HEADER';
<!DOCTYPE HTML>
<html lang="en" dir="ltr">
<head>
<meta charset="utf8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="Blood relatives timeline - A ged2site webpage">
<title>Blood Relatives' Timeline</title>
<link rel="stylesheet" href="/css/web.css" type="text/css" media="screen">
<style type="text/css">
body, html {
font-family: sans-serif;
font-size: 10px;
}
</style>
<script async type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.19.1/vis.min.js"></script>
<link async href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.19.1/vis.min.css" rel="stylesheet" type="text/css" />
<style type="text/css">
/* Limit the width of the biography box */
/*div.vis-tooltip { font-size:10px; white-space: normal; width: 30em; word-wrap: break-word; }*/
div.vis-tooltip {
font-size: 10px;
white-space: normal;
width: 30em;
max-width: 300px;
word-wrap: break-word;
padding: 5px;
}
</style>
</head>
<body>
<h1>Blood Relatives' Timeline</h1>
<p><font size=+1>
Click and move the mouse to move around the timeline.
Only people with known birth dates are shown.
</font></p>
<div id="visualization">
<div class="menu">
<input type="button" id="zoomIn" value="Zoom In"/>
<input type="button" id="zoomOut" value="Zoom Out"/>
<input type="button" id="moveLeft" value="Scroll Left"/>
<input type="button" id="moveRight" value="Scroll Right"/>
</div>
</div>
<script type="text/javascript">
// DOM element where the Timeline will be attached
var container = document.getElementById('visualization');
// Create a DataSet (allows two way data-binding)
var items = new vis.DataSet([
HEADER
# TODO: Add a -p option to do something like this - it's useful in debugging
# foreach my $person($ged->get_individual('Dolly Cowell')) {
# foreach my $person($ged->get_individual('Sophia Chapple')) {
foreach my $person(@everyone) {
$index++;
if(!$opts{'w'}) {
$| = 1;
$pr->update($index);
$pr->write();
$| = 0;
}
if(!$printed{$person->{'xref'}}) {
# FIXME: change é to e
print $xml "\n\t<person person_id=\"$index\">";
print_person({ person => $person });
print $xml "\n\t</person>";
print $csv "\n";
if($opts{'v'}) {
my $log = $geocoder->log();
$geocoder->flush();
foreach my $l(@{$log}) {
print $l->{location}, ': ' if($l->{'location'});
if($l->{geocoder}) {
if($l->{error}) {
print $l->{timetaken}, 's with ', $l->{geocoder}, '(', $l->{error}, ')';
} else {
print $l->{timetaken}, 's with ', $l->{geocoder};
}
} else {
print 'cached';
}
print ', wantarray ', $l->{wantarray}, "\n";
}
}
}
last if($opts{'L'} && ($index == $opts{'L'}));
last if(MAX_INDEX && ($index >= MAX_INDEX));
}
print $xml "\n</table>\n";
close $xml;
close $csv;
print $timeline_xml "</data>\n";
close $timeline_xml;
print $visjs <<'FOOTER';
]);
// Configuration for the Timeline
// var options = { zoomable: false, horizontalScroll: true, verticalScroll: true, autoResize: true, height: '500px', min: '1500', max: '2017' };
var timelineHeight = Math.round($(window).height() * 0.85) + 'px';
var options = {
zoomKey: 'ctrlKey',
verticalScroll: true,
min: '1500',
max: '2017',
height: timelineHeight
};
// Create a Timeline
var timeline = new vis.Timeline(container, items, options);
/**
* Move the timeline a given percentage to left or right
* @param {Number} percentage For example 0.1 (left) or -0.1 (right)
*/
function move (percentage) {
var range = timeline.getWindow();
var interval = range.end - range.start;
timeline.setWindow({
start: range.start.valueOf() - interval * percentage,
end: range.end.valueOf() - interval * percentage
});
}
// attach events to the navigation buttons
document.getElementById('zoomIn').onclick = function () { timeline.zoomIn( 0.2); };
document.getElementById('zoomOut').onclick = function () { timeline.zoomOut( 0.2); };
document.getElementById('moveLeft').onclick = function () { move( 0.2); };
document.getElementById('moveRight').onclick = function () { move(-0.2); };
</script>
</body>
</html>
FOOTER
close $visjs;
if(!$opts{'w'}) {
print "\n$index records processed\n";
}
my $name;
if($me) {
$name = 'of ' . $me->as_string(nee => 1);
} else {
$name = 'on this site';
}
if(scalar(%censuses)) {
print "Creating census index\n";
open(my $html, '>', 'static-site/censuses.html');
print $html "<html><head><title>Censuses in the Family Tree $name</title>",
"</head><body><center><h1>Censuses in the Family Tree $name</h1></center><br><ul>";
open($csv, '>', 'dynamic-site/databases/censuses.csv');
print $csv "entry!census!person\n";
$index = 1;
foreach my $census(sort keys(%censuses)) {
my $filename = $census;
$filename =~ tr/ /_/;
print $html "<li><a href=\"$filename.html\">$census</a></li>";
open(my $chtml, '>', "static-site/$filename.html");
print $chtml "<html><head><title>The Family Tree $name - $census</title>",
'</head>',
"<body><center><h1>The Family Tree $name - $census</h1>";
if($me) {
print $chtml '[ <a href="', make_filename_from_person(person => $me), '">Home</a> ]';
}
print $chtml ' | [ <a href="surnames.html">Surnames Index</a> ]';
if($opts{'w'}) {
print $chtml ' | [ <a href="todo.html">Errors</a> ]';
}
if($gedcal) {
print $chtml ' | [ <a href="calendar/index.html">Calendar</a> ]';
}
print $chtml ' | [ <a href="censuses.html">Census Index</a> ]',
' | [ <a href="history.html">Family History</a> ]</center><br>',
'<ul>';
foreach my $name(sort keys %{$censuses{$census}}) {
print $chtml '<li>',
'<a href="', make_filename_from_person(person => $censuses{$census}->{$name}), '">',
$name,
'</a></li>';
print $csv "$index!$census!", $censuses{$census}->{$name}->{'xref'}, "\n";
$index++;
}
print $chtml '</ul></body></html>';
close $chtml;
}
print $html '</ul></body></html>';
close $html;
close $csv;
}
if(scalar(%all_locations)) {
print "Creating locations database\n";
open($csv, '>', 'dynamic-site/databases/locations.csv');
print $csv "entry!location!person!year!date\n";
$index = 1;
open(my $locations_xml, '>', 'dynamic-site/databases/locations.xml');
print $locations_xml "<locations>\n\t<maps>\n";
my ($head, $body);
foreach my $year(sort keys(%all_locations)) {
my %markers;
foreach my $l(@{$all_locations{$year}}) {
my $place = place(record => $l->{'residence'}, nopreposition => 1);
$place =~ s/^\s*//;
push @{$markers{$place}}, $l;
print $csv "$index!$place!",
$l->{'person'}->as_string({ middle_names => 1, include_years => 1 }), '!',
"$year!",
$l->{'date'}, "\n";
$index++;
}
# Create a map of where everyone lived in each year
my %args = (geocoder => $geocoder);
if($javascript_key) {
$args{'api_key'} = $javascript_key;
}
my $map = HTML::GoogleMaps::V3->new(%args);
foreach my $place(keys %markers) {
my @annotations = @{$markers{$place}};
my $html;
my $previous_date;
foreach my $annotation(@annotations) {
my $date = $annotation->{'date'};
my $person = $annotation->{'person'};
if($previous_date && ($date eq $previous_date)) {
if($html) {
$html .= ', ';
}
} else {
if($html) {
$html .= '<br>';
}
$html .= "$date: ";
$previous_date = $date;
}
$html .= '<a href="?page=people&entry=' . $person->{'xref'} . '">' . $person->as_string() . '</a>';
}
add_marker(map => $map, place => HTML::Entities::decode($place), annotation => $html);
}
($head, $body) = $map->onload_render();
$head =~ s/\n\n*/\n/g;
$head =~ s/http:/https:/;
$head =~ s/</</g;
$head =~ s/>/>/g;
print $locations_xml "\t\t<map>\n\t\t\t<year>$year</year>\n\t\t\t<head>$head\n\t\t\t</head>\n\t\t</map>\n";
}
close $csv;
$body =~ s/</</g;
$body =~ s/>/>/g;
print $locations_xml "\t</maps>\n\t<body>$body</body>\n</locations>\n";
close $locations_xml;
}
if(scalar(%military)) {
print "Creating military records\n";
open($csv, '>', 'dynamic-site/databases/military.csv');
print $csv "entry!person!date!place!notes\n";
$index = 1;
foreach my $xref(sort keys(%military)) {
foreach my $entry(@{$military{$xref}}) {
print $csv "$index!$xref!", $entry->{'date'} || '', '!', $entry->{'place'} || '', '!', $entry->{'notes'} || '', "\n";
$index++;
}
}
close $csv;
}
if(scalar(%changes)) {
print "Adding to change blog\n";
open(my $log, '>>', 'change.psv');
my $date = DateTime->now(time_zone => 'local')->ymd('');
while(my $person = shift(@{$changes{'added_people'}})) {
print $log "$date|",
$person->{'xref'},
"|Added new person\n";
}
while(my $change = shift(@{$changes{'changes'}})) {
print $log "$date|",
$change->person()->{'xref'},
'|',
$change->change(),
"\n";
}
close $log;
}
if(scalar(%twins)) {
print "Creating twins index\n";
open($csv, '>', 'dynamic-site/databases/twins.csv');
print $csv "entry!twin\n";
foreach my $twin(sort keys(%twins)) {
print $csv "$twin!$twins{$twin}\n";
}
close $csv;
}
print "Creating surname index\n";
open(my $html, '>', 'static-site/surnames.html');
print $html "<html><head><title>Surnames in the Family Tree $name</title>",
"</head><body><center><h1>Surnames in the Family Tree $name</h1>";
if($me) {
print $html '[ <a href="', make_filename_from_person(person => $me), '">Home</a> ]';
}
print $html ' | [ <a href="surnames.html">Surnames Index</a> ]',
' | [ <a href="censuses.html">Census Index</a> ]',
' | [ <a href="calendar/index.html">Calendar</a> ]';
if($opts{'w'}) {
print $html ' | [ <a href="todo.html">Errors</a> ]';
}
print $html ' | [ <a href="history.html">Family History</a> ]</center><br><ul>';
open($csv, '>', 'dynamic-site/databases/surnames.csv');
print $csv "entry!surname!person\n";
$index = 1;
foreach my $surname(sort keys %{$surnames}) {
my $filename = $surname;
if($filename eq '') {
$filename = 'UNKNOWN';
}
print $html "<li><a href=\"$filename.html\">$filename</a> (";
my $count = scalar(keys %{$surnames->{$surname}});
if($count == 1) {
print $html '1 person';
} else {
print $html "$count people";
}
print $html ')</li>';
open(my $shtml, '>', "static-site/$filename.html");
print $shtml "<html><head><title>The Family Tree $name - $surname</title>",
'</head>',
"<body><center><h1>The Family Tree $name - $surname</h1>";
if($me) {
print $shtml '[ <a href="', make_filename_from_person(person => $me), '">Home</a> ]';
}
if($gedcal) {
print $shtml ' | [ <a href="calendar/index.html">Calendar</a> ]';
}
print $shtml ' | [ <a href="surnames.html">Surnames Index</a> ]',
' | [ <a href="history.html">Family History</a> ]';
if($opts{'w'}) {
print $shtml ' | [ <a href="todo.html">Errors</a> ]';
}
print $shtml ' | [ <a href="censuses.html">Census Index</a> ]</center><br>',
'<ul>';
foreach my $person(sort keys %{$surnames->{$surname}}) {
# print "\t$person maps to ", $surnames->{$surname}->{$person}, "\n";
print $shtml '<li>',
'<a href="', make_filename_from_person(person => $surnames->{$surname}->{$person}), "\">$person</a>",
'</li>';
print $csv "$index!$filename!", $surnames->{$surname}->{$person}->{'xref'}, "\n";
$index++;
}
print $shtml '</ul></body></html>';
close $shtml;
}
close $csv;
print $html '</ul></body></html>';
close $html;
if((!defined($key)) && defined($config)) {
$key = $config->{'google_verification'};
}
if($key) {
open($html, '>', "static-site/$key.html");
print $html "google-site-verification: $key.html";
close $html;
if(-r "dynamic-site/$key.html") {