/[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 6 by dpavlin, Wed Dec 12 12:48:42 2007 UTC revision 12 by dpavlin, Wed Dec 12 14:10:37 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 68  sub surround { Line 79  sub surround {
79          return $with . $what . $with;          return $with . $what . $with;
80  }  }
81    
82    sub pre {
83            my $text = shift;
84            $text =~ s/^{{{//;
85            $text =~ s/}}}$//;
86            return '.pre' . $text . '.pre';
87    }
88    
89  my $count = 0;  my $count = 0;
90    
91  foreach my $name ( keys %$page ) {  foreach my $name ( keys %$page ) {
# Line 82  foreach my $name ( keys %$page ) { Line 100  foreach my $name ( keys %$page ) {
100          $body =~ s/''''(.+?)''''/surround('`',$1)/gse;          $body =~ s/''''(.+?)''''/surround('`',$1)/gse;
101          $body =~ s/'''(.+?)'''/surround('*',$1)/gse;          $body =~ s/'''(.+?)'''/surround('*',$1)/gse;
102          $body =~ s/''(.+?)''/surround('_',$1)/gse;          $body =~ s/''(.+?)''/surround('_',$1)/gse;
103            $body =~ s/$RE{balanced}{-begin => "{{{"}{-end => "}}}"}{-keep}/pre($1)/gse;
104    
105            # fix bullets
106            $body =~ s/^\s+([\*])/$1/gm;
107    
108            # fix links
109            $body =~ s/\["([^"]+)"\]/[$1]/gs;
110            $body =~ s,\[(http://\S+)\s+([^\]]+)\],"$2"<$1>,gs;
111            $body =~ s,\[(http://[^\]]+)\],$1,gs;
112            $body =~ s,$page_link_re,[$1],gs;
113    
114          Encode::_utf8_off( $body );          Encode::_utf8_off( $body );
115    
# Line 89  foreach my $name ( keys %$page ) { Line 117  foreach my $name ( keys %$page ) {
117    
118          if ( $name =~ m!/! ) {          if ( $name =~ m!/! ) {
119                  my @page_tags = split(m!/!, $name);                  my @page_tags = split(m!/!, $name);
120                  pop @page_tags; # remove page name                  $name = pop @page_tags; # remove page name
121                  push @tags, @page_tags;                  push @tags, @page_tags;
                 $name =~ s!/!_!g;  
122          }          }
123    
124          $Rester->put_page( $name, {          $Rester->put_page( $name, {

Legend:
Removed from v.6  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26