/[Grep]/lib/Grep/Import/ScrapBook.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /lib/Grep/Import/ScrapBook.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 178 by dpavlin, Sat Aug 11 17:41:42 2007 UTC revision 179 by dpavlin, Mon Sep 3 16:06:28 2007 UTC
# Line 66  sub import { Line 66  sub import {
66          Jifty->log->info( "Using user ", $owner->id, " from ", $owner->email, " for import" );          Jifty->log->info( "Using user ", $owner->id, " from ", $owner->email, " for import" );
67    
68          my $feed = Grep::Model::Feed->new( current_user => $owner );          my $feed = Grep::Model::Feed->new( current_user => $owner );
69    
70          $feed->load_or_create(          $feed->load_or_create(
71                  uri => 'file://' . $path,                  uri => 'file://' . $path,
72                  title => 'ScrapBook',                  title => 'ScrapBook',
# Line 105  sub import { Line 106  sub import {
106                          $stats->{failure}++;                          $stats->{failure}++;
107                          next;                          next;
108                  }                  }
                 my $content = read_file( $content_path ) or  
                         die "can't read $content_path: $!";  
   
                 my $tree = HTML::TreeBuilder->new or die "can't create html tree";  
                 $tree->parse( $content ) or die "can't parse fetched content";  
   
                 my $body = $tree->look_down( '_tag', 'body' );  
   
                 my $resolver = HTML::ResolveLink->new( base => '/static/' . $config->{Dir} . $rel_path );  
                 $content = $resolver->resolve( $body->as_HTML );  
109    
110                  # create date from id                  # create date from id
111    
112                  my $dt;                  my $dt;
113                  if ( $hash->{id} =~ m/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ ) {                  if ( $hash->{id} =~ m/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ ) {
114                          $dt = DateTime->new(                          $dt = Jifty::DateTime->new(
115                                  year    => $1,                                  year    => $1,
116                                  month   => $2,                                  month   => $2,
117                                  day             => $3,                                  day             => $3,
# Line 134  sub import { Line 125  sub import {
125                  }                  }
126    
127                  my $i = Grep::Model::Item->new( current_user => $owner );                  my $i = Grep::Model::Item->new( current_user => $owner );
128                  my ($ok,$msg) = $i->load_or_create(  
129                    if ( $i->load_by_cols(
130                          in_feed => $feed,                          in_feed => $feed,
131                          title => $hash->{title},                          title => $hash->{title},
132                          link => $hash->{source},                          link => $hash->{source},
133                          content => $content,                  ) ) {
134  #                       created_on => $dt,                          $stats->{old}++;
135                  );                          Jifty->log->info("existing ", $i->id ," ", $i->link);
136                    } else {
137    
138                  $i->set_created_on( $dt );                          my $content = read_file( $content_path ) or
139                                    die "can't read $content_path: $!";
140    
141                  if ( ! $ok ) {                          my $tree = HTML::TreeBuilder->new or die "can't create html tree";
142                          Jifty->log->error( $msg );                          $tree->parse( $content ) or die "can't parse fetched content";
                         $stats->{failure}++;  
                         next;  
                 }  
143    
144                  if ( $msg && $msg =~ m/^Found/ ) {                          my $body = $tree->look_down( '_tag', 'body' );
                         $stats->{old}++;  
                 } else {  
                         $stats->{new}++;  
                         Jifty->log->info("created ", $i->id ," ", $i->link, " ", length( $content ), " bytes");  
                         $search->add( $i, $owner->id );  
                 }  
145    
146                            my $resolver = HTML::ResolveLink->new( base => '/static/' . $config->{Dir} . $rel_path );
147                            $content = $resolver->resolve( $body->as_HTML );
148    
149                            my ($ok,$msg) = $i->create(
150                                    in_feed => $feed,
151                                    created_on => $dt,
152                                    title => $hash->{title},
153                                    link => $hash->{source},
154                                    content => $content,
155                            );
156    
157    #                       $i->set_created_on( $dt );
158    
159                            if ( ! $ok ) {
160                                    Jifty->log->error( $msg );
161                                    $stats->{failure}++;
162                                    next;
163                            }
164    
165                            if ( $msg && $msg !~ m/^Found/ ) {
166                                    $stats->{new}++;
167                                    Jifty->log->info("created ", $i->id ," ", $i->link, " ", length( $content ), " bytes");
168                                    $search->add( $i, $owner->id );
169                            } else {
170                                    Jifty->log->info("skipped ", $i->id ," ", $i->link, " ", length( $content ), " bytes");
171                            }
172                    }
173          }          }
174    
175          $search->finish;          $search->finish;

Legend:
Removed from v.178  
changed lines
  Added in v.179

  ViewVC Help
Powered by ViewVC 1.1.26