/[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 7 by dpavlin, Wed Dec 12 13:09:29 2007 UTC revision 11 by dpavlin, Wed Dec 12 14:04:11 2007 UTC
# Line 11  use Encode; Line 11  use Encode;
11  use HTTP::Date;  use HTTP::Date;
12  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
13    
14  my $max = 2;  my $max = 999;
15    
16  my $page;  my $page;
17  my $page_date;  my $page_date;
18    
19    my @page_names;
20    
21  find({  find({
22          wanted => sub {          wanted => sub {
23                  my $path = $File::Find::name;                  my $path = $File::Find::name;
# Line 25  find({ Line 27  find({
27                  my $ref = XMLin( $path ) || die "can't open $path: $!";                  my $ref = XMLin( $path ) || die "can't open $path: $!";
28    
29                  my $name = $ref->{name} || die "no name in $path";                  my $name = $ref->{name} || die "no name in $path";
30    
31                    return if $name =~ m/^TamSystem/;
32    
33                  my $date =  $ref->{meta}->{LastModified};                  my $date =  $ref->{meta}->{LastModified};
34                  if ( ! $date ) {                  if ( ! $date ) {
35                          warn "SKIP: no LastModified in $path $name";                          warn "SKIP: no LastModified in $path $name";
# Line 37  find({ Line 42  find({
42    
43                  $page->{ $name } = [ $data, $date ];                  $page->{ $name } = [ $data, $date ];
44    
45                    # strip path from page name
46                    $name =~ s,^.+/([^/]+)$,$1,;
47                    push @page_names, $name;
48    
49                  #warn dump( $ref );                  #warn dump( $ref );
50          },          },
51  }, shift @ARGV || '.');  }, shift @ARGV || '.');
52    
53  my @pages = ( keys %$page );  my @pages = ( keys %$page );
54    
55  warn "found following pages: ", join(", ", @pages),"\n";  warn "found following pages: ", join(", ", @page_names),"\n";
56    
57    my $page_link_re = '\b(' . join('|', @page_names) . ')\b';
58    
59  my $Rester = Socialtext::Resting->new(  my $Rester = Socialtext::Resting->new(
60          username => 'tamtam',          username => 'tamtam',
# Line 59  sub header { Line 70  sub header {
70                  my $level = length($1);                  my $level = length($1);
71                  return "\n" . ( '^' x $level ) . " $2\n";                  return "\n" . ( '^' x $level ) . " $2\n";
72          } else {          } else {
73                  die "can't parse header: $h";                  return $h;
74          }          }
75  }  }
76    
# Line 83  foreach my $name ( keys %$page ) { Line 94  foreach my $name ( keys %$page ) {
94          $body =~ s/'''(.+?)'''/surround('*',$1)/gse;          $body =~ s/'''(.+?)'''/surround('*',$1)/gse;
95          $body =~ s/''(.+?)''/surround('_',$1)/gse;          $body =~ s/''(.+?)''/surround('_',$1)/gse;
96    
97            # fix bullets
98          $body =~ s/^\s+([\*])/$1/gm;          $body =~ s/^\s+([\*])/$1/gm;
99    
100            # fix links
101            $body =~ s/\["([^"]+)"\]/[$1]/gs;
102            $body =~ s,\[(http://\S+)\s+([^\]]+)\],"$2"<$1>,gs;
103            $body =~ s,\[(http://[^\]]+)\],$1,gs;
104            $body =~ s,$page_link_re,[$1],gs;
105    
106          Encode::_utf8_off( $body );          Encode::_utf8_off( $body );
107    
108          my @tags = ( 'TamTam' );          my @tags = ( 'TamTam' );
109    
110          if ( $name =~ m!/! ) {          if ( $name =~ m!/! ) {
111                  my @page_tags = split(m!/!, $name);                  my @page_tags = split(m!/!, $name);
112                  pop @page_tags; # remove page name                  $name = pop @page_tags; # remove page name
113                  push @tags, @page_tags;                  push @tags, @page_tags;
                 $name =~ s!/!_!g;  
114          }          }
115    
116          $Rester->put_page( $name, {          $Rester->put_page( $name, {

Legend:
Removed from v.7  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26