/[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 21 by dpavlin, Thu Dec 13 11:39:52 2007 UTC revision 26 by dpavlin, Fri Dec 14 23:46:57 2007 UTC
# Line 17  use Data::Dump qw/dump/; Line 17  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(  GetOptions(
23          'debug+' => \$debug,          'debug+' => \$debug,
24          'max=i' => \$max,          'max=i' => \$max,
25            'attachments' => \$attachments,
26  );  );
27    
28  my $page;  my $page;
# Line 28  my $page_date; Line 30  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 41  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 83  find({ Line 85  find({
85    
86                  $page->{ $name } = {                  $page->{ $name } = {
87                          content => convert_markup( $data ),                          content => convert_markup( $data ),
88                            original => $data,
89                          date => convert_date( $date ),                          date => convert_date( $date ),
90                          attachments => $attachments,                          attachments => $attachments,
91                  };                  };
# Line 131  sub surround { Line 134  sub surround {
134    
135  sub pre {  sub pre {
136          my $text = shift;          my $text = shift;
137          $text =~ s/^{{{//;          $text =~ s/^{{{\s*//s;
138          $text =~ s/}}}$//;          $text =~ s/\s*}}}$//s;
139          return '.pre' . $text . '.pre';          return "\n.pre\n" . $text . "\n.pre\n";
140  }  }
141    
142  sub convert_markup {  sub convert_markup {
# Line 195  foreach my $name ( keys %$page ) { Line 198  foreach my $name ( keys %$page ) {
198          $body =~ s,``,,gs;          $body =~ s,``,,gs;
199    
200          $body .= qq{          $body .= qq{
201    
202  ----  ----
203    
204  "original"<http://www.razmjenavjestina.org/$full_name> {date: $date}  "original"<http://www.razmjenavjestina.org/$full_name> {date: $date}
# Line 202  foreach my $name ( keys %$page ) { Line 206  foreach my $name ( keys %$page ) {
206    
207          Encode::_utf8_off( $body );          Encode::_utf8_off( $body );
208    
         $Rester->put_page( $name, { content => $body, date => $date });  
209          print "$name $date\n";          print "$name $date\n";
210    
211            # original markup
212            $Rester->put_page( $name, { content => $p->{original}, date => $date });
213    
214          foreach ( @tags ) {          foreach ( @tags ) {
215                  $Rester->put_pagetag( $name, $_ );                  $Rester->put_pagetag( $name, $_, { date => $date } );
216                  print "+ tag $_\n";                  print "+ tag $_\n";
217          }          }
218          foreach my $a ( @{ $p->{attachments} } ) {  
219                  my $type = $m->get_mime( $a->{full_path} );          if ( $attachments ) {
220                  my $content = read_file( $a->{full_path} );                  foreach my $a ( @{ $p->{attachments} } ) {
221                  print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n";                          my $type = $m->get_mime( $a->{full_path} );
222                  $Rester->post_attachment($name, $a->{name}, $content, $type );                          my $content = read_file( $a->{full_path} );
223                            print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n";
224                            $Rester->post_attachment($name, $a->{name}, $content, $type );
225                    }
226          }          }
227    
228            # converted page
229            $Rester->put_page( $name, { content => $body, date => $date });
230    
231  }  }
232    

Legend:
Removed from v.21  
changed lines
  Added in v.26

  ViewVC Help
Powered by ViewVC 1.1.26