#!/pkg/bin/perl use strict; use constant MTDIR => "/home/mt/MT"; use lib MTDIR . '/lib'; use MT; my $blog_id = 1; my $mt = MT->new; use Date::Parse qw(str2time); use Date::Format qw(time2str); use Data::Dumper; use HTML::Entities; my $entry_id; my $in_comments = 0; my %comment; my $comments; sub flush { return 1 unless $comment{id}; $comment{text} =~ s!^

!!sm; $comment{text} =~ s!
\n!\n!smg; $comment{text} =~ s!\s*

\s*$!!sm; $comment{text} =~ s!^\s*!!; $comment{text} =~ s!\s*$!!s; $comment{entry_id} = $entry_id; print Data::Dumper->Dump([\%comment], [qw(comment)]); my $entry = MT::Entry->load({id => $comment{entry_id}}); my $comment = MT::Comment->load({ id => $comment{id} }); if ($comment) { print "comment id already exists\n"; if ($comment{author} eq $comment->author) { %comment = (); return 1; } die "not the same comment?"; } else { $comment = MT::Comment->new(); $comment->id($comment{id}); $comment->blog_id($entry->blog_id); $comment->entry_id($entry->id); $comment->author($comment{author}); $comment->url($comment{link}); $comment->text($comment{text}); $comment->email($comment{email}) if $comment{email}; $comment->created_on(time2str("%Y%m%d%H%M%S", $comment{time}) ); $comment->save or die $comment->errstr; $comments++; print "COMMENTS LOADED: $comments\n"; } %comment = (); 1; } while (<>) { $entry_id = $1 if m!rdf:about="http://www.askbjoernhansen.com/archives/\d{4}/\d{2}/\d\d/0*(\d+).html"!; unless ($in_comments) { $in_comments = 1 if m!^

Comments

!; next; } if (m!^

Post a comment

!) { flush; $in_comments = 0; next; } if (my ($author, $date) = ($_ =~ m!

Posted by: (.*) at (.*)

!)) { if ($author =~ m/^\s*(.*?)\s*!); ($comment{email}) = ($author =~ m!!); $comment{email} = decode_entities($comment{email}) if $comment{email}; } else { $author =~ s/^\s*//; $author =~ s/\s*$//; $comment{author} = $author; } $comment{author_string} = $author; #$comment{date} = $date; $comment{time} = str2time($date); flush; next; } flush and $comment{id} = $1 and next if m!^!; $comment{text} .= $_; }