/[socialtext-import]/tamtam/tamtam2socialtext.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 /tamtam/tamtam2socialtext.pl

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

revision 19 by dpavlin, Wed Dec 12 23:08:14 2007 UTC revision 24 by dpavlin, Thu Dec 13 12:42:45 2007 UTC
# Line 12  use HTTP::Date; Line 12  use HTTP::Date;
12  use POSIX qw/strftime/;  use POSIX qw/strftime/;
13  use File::Slurp;  use File::Slurp;
14  use File::MMagic::XS;  use File::MMagic::XS;
15    use Getopt::Long;
16  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
17    
18  my $debug = 0;  my $debug = 0;
19  my $max = 999;  my $max = 999;
20    my $attachments = 0;
21    
22    GetOptions(
23            'debug+' => \$debug,
24            'max=i' => \$max,
25            'attachments' => \$attachments,
26    );
27    
28  my $page;  my $page;
29  my $page_date;  my $page_date;
30    
31  my @page_names;  my @page_names;
32    
33  print "Collecting pages...\n";  print "Importing $max pages", $attachments ? " with attachments" : "", "...\n";
34    
35  find({  find({
36          wanted => sub {          wanted => sub {
# Line 35  find({ Line 43  find({
43                                  'attachment' => '+name',                                  'attachment' => '+name',
44                                  'meta' => 'name',                                  'meta' => 'name',
45                          },                          },
46                          ForceArray => [ 'attachment', 'widget' ],                          ForceArray => [ 'attachment', 'meta', 'widget' ],
47                  ) || die "can't open $path: $!";                  ) || die "can't open $path: $!";
48    
49                  warn "## $path = ",dump( $ref ) if $debug;                  warn "## $path = ",dump( $ref ) if $debug;
# Line 189  foreach my $name ( keys %$page ) { Line 197  foreach my $name ( keys %$page ) {
197          $body =~ s,``,,gs;          $body =~ s,``,,gs;
198    
199          $body .= qq{          $body .= qq{
200    
201  ----  ----
202    
203  Original http://www.razmjenavjestina.org/$full_name {date: $date}  "original"<http://www.razmjenavjestina.org/$full_name> {date: $date}
204  };  };
205    
206          Encode::_utf8_off( $body );          Encode::_utf8_off( $body );
# Line 202  Original http://www.razmjenavjestina.org Line 211  Original http://www.razmjenavjestina.org
211                  $Rester->put_pagetag( $name, $_ );                  $Rester->put_pagetag( $name, $_ );
212                  print "+ tag $_\n";                  print "+ tag $_\n";
213          }          }
214          foreach my $a ( @{ $p->{attachments} } ) {  
215                  my $type = $m->get_mime( $a->{full_path} );          if ( $attachments ) {
216                  my $content = read_file( $a->{full_path} );                  foreach my $a ( @{ $p->{attachments} } ) {
217                  print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n";                          my $type = $m->get_mime( $a->{full_path} );
218                  $Rester->post_attachment($name, $a->{name}, $content, $type );                          my $content = read_file( $a->{full_path} );
219                            print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n";
220                            $Rester->post_attachment($name, $a->{name}, $content, $type );
221                    }
222          }          }
223    
224  }  }

Legend:
Removed from v.19  
changed lines
  Added in v.24

  ViewVC Help
Powered by ViewVC 1.1.26