/[couchdb]/scripts/reblog2couchdb.pl
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 /scripts/reblog2couchdb.pl

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

revision 35 by dpavlin, Sat Apr 25 00:11:51 2009 UTC revision 36 by dpavlin, Tue Apr 28 21:34:58 2009 UTC
# Line 29  $dbh->do(qq{ Line 29  $dbh->do(qq{
29    
30  my $sql = qq{  my $sql = qq{
31          select          select
32                  items.id as _id,                  i.id as item_id,
33                  items.*,  --              i.guid as _id,
34                  feeds.url as feed_url,                  i.link as _id,
35                  feeds.title as feed_title,                  i.*,
36                  feeds.link as feed_link,                  f.url as feed_url,
37                  feeds.description as feed_description                  f.title as feed_title,
38          from items                  f.link as feed_link,
39          join published_items on items.id = item_id                  f.description as feed_description
40          join feeds on items.feed_id = feeds.id          from items i
41          where items.id > ?          join published_items p on i.id = p.item_id
42          order by items.id asc          join feeds f on i.feed_id = f.id
43            where i.id > ?
44            order by i.id asc
45          limit 1000          limit 1000
46  };  };
47    
# Line 96  my $count = 0; Line 98  my $count = 0;
98  my $row_tags = $sth_tags->fetchrow_hashref();  my $row_tags = $sth_tags->fetchrow_hashref();
99    
100  while (my $row = $sth->fetchrow_hashref() ) {  while (my $row = $sth->fetchrow_hashref() ) {
101          my $_id = $row->{_id} || die "row needs _id";          my $_id = $row->{_id} || "c$count";
102            $_id =~ s{\W+}{_}g;
103            $_id =~ s{_+$}{};
104          my $doc = $db->newDoc( $_id );          my $doc = $db->newDoc( $_id );
105    
106          while ( $row_tags && $row_tags->{item_id} < $row->{_id} ) {          while ( $row_tags && $row_tags->{item_id} < $row->{item_id} ) {
107                  $row_tags = $sth_tags->fetchrow_hashref();                  $row_tags = $sth_tags->fetchrow_hashref();
108                  warn "## got tags: ",dump( $row_tags ) if $debug;                  warn "## got tags: ",dump( $row_tags ) if $debug;
109          }          }
# Line 110  while (my $row = $sth->fetchrow_hashref( Line 114  while (my $row = $sth->fetchrow_hashref(
114                  $doc->addAttachment( 'item.xml', 'application/xhtml+xml', $a ) if $a;                  $doc->addAttachment( 'item.xml', 'application/xhtml+xml', $a ) if $a;
115                  $a = delete( $row->{content} );                  $a = delete( $row->{content} );
116                  $doc->addAttachment( 'content.html', 'text/html', $a ) if $a;                  $doc->addAttachment( 'content.html', 'text/html', $a ) if $a;
117                  if ( $row_tags && $row_tags->{item_id} == $row->{_id} ) {                  if ( $row_tags && $row_tags->{item_id} == $row->{item_id} ) {
118                          $row->{tags} = [ split(/\s+/, $row_tags->{tags} ) ];                          $row->{tags} = [ split(/\s+/, $row_tags->{tags} ) ];
119                          warn "++ ",$row->{item_id}, dump( $row->{tags} );                          warn "++ ",$row->{item_id}, dump( $row->{tags} );
120                  }                  }

Legend:
Removed from v.35  
changed lines
  Added in v.36

  ViewVC Help
Powered by ViewVC 1.1.26