From: Dobrica Pavlinusic Date: Fri, 12 Nov 2010 21:38:36 +0000 (+0100) Subject: cleanup json generation and dump xml from it X-Git-Url: http://git.rot13.org/?p=NoSQL-toys.git;a=commitdiff_plain;h=2773a93d9cdba58fa2c53936a2e503d67fef97a8 cleanup json generation and dump xml from it --- diff --git a/reblog/reblog-published.pl b/reblog/reblog-published.pl index 388ba66..db0ac9d 100755 --- a/reblog/reblog-published.pl +++ b/reblog/reblog-published.pl @@ -1,5 +1,5 @@ -#!/usr/bin/perl -w - +#!/usr/bin/perl +use warnings; use strict; use DBI; use Data::Dump qw/dump/; @@ -36,9 +36,18 @@ $dbh->do(qq{ my $sql = qq{ select i.id as item_id, --- i.guid as _id, - i.link as _id, - i.*, + md5(i.guid) as _id, + + i.guid, + i.link, + i.title, + i.content, + i.author, + i.category, + i.modified, + i.timestamp, + i.insert_timestamp, + f.url as feed_url, f.title as feed_title, f.link as feed_link, @@ -68,7 +77,7 @@ order by items_userdata.item_id asc my $last_row = 0; # FIXME $last_row = 0 if $debug; -print "Fetching items from $dbi id > $last_row [$offset $limit]\n"; +warn "Fetching items from $dbi id > $last_row [$offset $limit]\n"; my $sth = $dbh->prepare($sql); $sth->execute( $last_row ); @@ -98,13 +107,17 @@ while (my $row = $sth->fetchrow_hashref() ) { $row->{feed} = $feed; while ( $row_tags && $row_tags->{item_id} < $row->{item_id} ) { - $row_tags = $sth_tags->fetchrow_hashref(); - warn "## got tags: ",dump( $row_tags ) if $debug; - $row->{tags} = [ split(/\s+/, $row_tags->{tags} ) ]; + if ( $row_tags = $sth_tags->fetchrow_hashref() ) { + warn "## got tags: ",dump( $row_tags ) if $debug; + $row->{tags} = [ split(/\s+/, $row_tags->{tags} ) ]; + } else { + warn "end of tags"; + $row_tags = undef; + } } # warn dump($row); - print encode_json $row; + print encode_json($row),$/; }