-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.pl
executable file
·102 lines (82 loc) · 3.07 KB
/
register.pl
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
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use open qw(:std :utf8);
use YAML ();
my ($meta, $data) = YAML::LoadFile($ARGV[0]);
my $films = YAML::LoadFile('films.yaml');
unless ($data) {
$data = $meta;
$meta = undef;
}
if ($meta) {
printf("### %s\n\n", $meta->{title});
}
if (%$data) {
foreach my $place ( sort keys %$data ) {
printf("- [%s](#%s)\n", $place, join('-', split(/[\s,]+/, $place)));
}
print("\n");
foreach my $place ( sort keys %$data ) {
my $dp = $data->{$place};
printf("#### %s\n\n", $place);
if (!ref $dp || ref $dp eq 'ARRAY') {
my @l = ref $dp ? @$dp : defined $dp ? $dp : ();
if (@l) {
print("См. " . join(", ", map { sprintf("[%s](#%s)", $_, join('-', split(/[\s,]+/, $_))) } sort @l) . ".\n\n");
}
else {
warn("No place link for \"" . $place . "\"\n");
}
next;
}
if (my @r = sort grep { my $v = $data->{$_}; defined($v) && (!ref($v) && $v eq $place || ref($v) eq 'ARRAY' && grep { $_ eq $place } @$v) } keys %$data) {
printf("Также %s.\n\n", join(', ', @r));
}
for my $t (sort keys %$dp) {
my $d = $dp->{$t};
printf("##### %s\n\n", $t);
for my $y (sort keys %$d) {
my @l = ref $d->{$y} eq 'ARRAY' ? @{$d->{$y}} : $d->{$y};
printf("- %s — ", $y);
for (0 .. $#l) {
next unless defined $l[$_];
unless (ref $l[$_]{u} eq 'ARRAY') {
unshift(@{$l[$_]{p}}, 'ГАРТ') if @{$l[$_]{p}} < 4;
printf("[%s, ф. %s, оп. %s, д. %s](%s)", @{$l[$_]{p}}, $l[$_]{u});
next;
}
my @m = ref $l[$_]{u}[0] ? @{$l[$_]{u}} : $l[$_]{u};
my $f = '';
unshift(@{$l[$_]{p}}, 'ГАРТ') if @{$l[$_]{p}} < 4;
printf("%s, ф. %s, оп. %s, д. %s: ", @{$l[$_]{p}});
for (0 .. $#m) {
if (!$f || $m[$_][0] ne $f) {
printf('[#%s[', $films->{$m[$_][0]} // '{' . $m[$_][0] . '}');
$f = $m[$_][0];
}
else {
print('[[');
}
if (defined $m[$_][2]) {
printf('%d—%d', $m[$_][1] + 1, $m[$_][2] + 1);
}
else {
printf('%d', $m[$_][1] + 1);
}
printf(']](https://www.familysearch.org/search/film/%s?i=%d)', $m[$_][0], $m[$_][1]);
}
continue {
print(', ') if $_ < $#m;
}
}
continue {
print('; ') if $_ < $#l;
}
print("\n");
}
print("\n");
}
}
}