12 |
use POSIX qw/strftime/; |
use POSIX qw/strftime/; |
13 |
use File::Slurp; |
use File::Slurp; |
14 |
use File::MMagic::XS; |
use File::MMagic::XS; |
15 |
|
use Getopt::Long; |
16 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
17 |
|
|
18 |
my $debug = 0; |
my $debug = 0; |
19 |
my $max = 999; |
my $max = 999; |
20 |
|
my $attachments = 0; |
21 |
|
|
22 |
|
GetOptions( |
23 |
|
'debug+' => \$debug, |
24 |
|
'max=i' => \$max, |
25 |
|
'attachments' => \$attachments, |
26 |
|
); |
27 |
|
|
28 |
my $page; |
my $page; |
29 |
my $page_date; |
my $page_date; |
30 |
|
|
31 |
my @page_names; |
my @page_names; |
32 |
|
|
33 |
print "Collecting pages...\n"; |
print "Importing $max pages", $attachments ? " with attachments" : "", "...\n"; |
34 |
|
|
35 |
find({ |
find({ |
36 |
wanted => sub { |
wanted => sub { |
43 |
'attachment' => '+name', |
'attachment' => '+name', |
44 |
'meta' => 'name', |
'meta' => 'name', |
45 |
}, |
}, |
46 |
ForceArray => [ 'attachment', 'widget' ], |
ForceArray => [ 'attachment', 'meta', 'widget' ], |
47 |
) || die "can't open $path: $!"; |
) || die "can't open $path: $!"; |
48 |
|
|
49 |
warn "## $path = ",dump( $ref ) if $debug; |
warn "## $path = ",dump( $ref ) if $debug; |
197 |
$body =~ s,``,,gs; |
$body =~ s,``,,gs; |
198 |
|
|
199 |
$body .= qq{ |
$body .= qq{ |
200 |
|
|
201 |
---- |
---- |
202 |
|
|
203 |
"original"<http://www.razmjenavjestina.org/$full_name> {date: $date} |
"original"<http://www.razmjenavjestina.org/$full_name> {date: $date} |
211 |
$Rester->put_pagetag( $name, $_ ); |
$Rester->put_pagetag( $name, $_ ); |
212 |
print "+ tag $_\n"; |
print "+ tag $_\n"; |
213 |
} |
} |
214 |
foreach my $a ( @{ $p->{attachments} } ) { |
|
215 |
my $type = $m->get_mime( $a->{full_path} ); |
if ( $attachments ) { |
216 |
my $content = read_file( $a->{full_path} ); |
foreach my $a ( @{ $p->{attachments} } ) { |
217 |
print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n"; |
my $type = $m->get_mime( $a->{full_path} ); |
218 |
$Rester->post_attachment($name, $a->{name}, $content, $type ); |
my $content = read_file( $a->{full_path} ); |
219 |
|
print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n"; |
220 |
|
$Rester->post_attachment($name, $a->{name}, $content, $type ); |
221 |
|
} |
222 |
} |
} |
223 |
|
|
224 |
} |
} |