17 |
|
|
18 |
or modify L<ScrapBookDir> path (relative to Grep installation static root). |
or modify L<ScrapBookDir> path (relative to Grep installation static root). |
19 |
|
|
|
=head1 SEE ALSO |
|
|
|
|
|
L<http://amb.vis.ne.jp/mozilla/scrapbook/> - ScrapBook FireFox extension |
|
|
|
|
20 |
=cut |
=cut |
21 |
|
|
22 |
use XML::Simple; |
use XML::Simple; |
55 |
#source => 'Grep::Source', |
#source => 'Grep::Source', |
56 |
); |
); |
57 |
|
|
58 |
|
my $stats; |
59 |
|
|
60 |
foreach my $item ( @{ $rdf->{'RDF:Description'} } ) { |
foreach my $item ( @{ $rdf->{'RDF:Description'} } ) { |
61 |
|
|
62 |
warn "## item = ",dump( $item ); |
$stats->{total}++; |
63 |
|
|
64 |
|
#warn "## item = ",dump( $item ); |
65 |
|
|
66 |
my $hash; |
my $hash; |
67 |
foreach my $k ( keys %$item ) { |
foreach my $k ( keys %$item ) { |
72 |
$hash->{$n} = $item->{$k}; |
$hash->{$n} = $item->{$k}; |
73 |
} |
} |
74 |
|
|
75 |
warn "## hash = ", dump( $hash ); |
#warn "## hash = ", dump( $hash ); |
76 |
|
|
77 |
|
|
78 |
# fetch full-text content and import it |
# fetch full-text content and import it |
80 |
my $content_path = $dir . '/data/' . $hash->{id} . '/index.html'; |
my $content_path = $dir . '/data/' . $hash->{id} . '/index.html'; |
81 |
if ( ! -r $content_path ) { |
if ( ! -r $content_path ) { |
82 |
Jifty->log->warn("can't import $content_path: $!"); |
Jifty->log->warn("can't import $content_path: $!"); |
83 |
|
$stats->{failure}++; |
84 |
next; |
next; |
85 |
} |
} |
86 |
my $content = read_file( $content_path ) or |
my $content = read_file( $content_path ) or |
104 |
warn "can't parse date from ", $hash->{id}; |
warn "can't parse date from ", $hash->{id}; |
105 |
} |
} |
106 |
|
|
|
|
|
107 |
my $i = Grep::Model::Item->new(); |
my $i = Grep::Model::Item->new(); |
108 |
my ($id,$msg) = $i->load_or_create( |
my ($ok,$msg) = $i->load_or_create( |
109 |
in_feed => $feed, |
in_feed => $feed, |
110 |
title => $hash->{title}, |
title => $hash->{title}, |
111 |
link => $hash->{source}, |
link => $hash->{source}, |
113 |
issued => $hash->{id}, |
issued => $hash->{id}, |
114 |
); |
); |
115 |
|
|
116 |
|
if ( ! $ok ) { |
117 |
|
Jifty->log->error( $msg ); |
118 |
|
$stats->{failure}++; |
119 |
|
next; |
120 |
|
} |
121 |
|
|
122 |
warn ">> item $id $msg\n"; |
if ( $msg && $msg =~ m/^Found/ ) { |
123 |
|
$stats->{old}++; |
124 |
|
} else { |
125 |
|
$stats->{new}++; |
126 |
|
Jifty->log->info("imported ", $i->id ," ", $i->link, " ", length( $content ), " bytes"); |
127 |
|
$search->add( $i, $i->in_feed->owner->id ); |
128 |
|
} |
129 |
|
|
130 |
} |
} |
131 |
|
|
132 |
return 1; |
return $stats; |
133 |
} |
} |
134 |
|
|
135 |
|
=head1 SEE ALSO |
136 |
|
|
137 |
|
L<http://amb.vis.ne.jp/mozilla/scrapbook/> - ScrapBook FireFox extension |
138 |
|
|
139 |
|
=cut |
140 |
|
|
141 |
1; |
1; |