/[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 5 by dpavlin, Wed Dec 12 12:12:21 2007 UTC revision 9 by dpavlin, Wed Dec 12 13:22:32 2007 UTC
# Line 8  use File::Find; Line 8  use File::Find;
8  use Regexp::Common qw/balanced/;  use Regexp::Common qw/balanced/;
9  use Socialtext::Resting;  use Socialtext::Resting;
10  use Encode;  use Encode;
11    use HTTP::Date;
12  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
13    
14    my $max = 5;
15    
16  my $page;  my $page;
17    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;
24                  return unless -f $path;                  return unless -f $path;
25    
26                  warn "# $path\n";                  warn "# $path\n";
27                  my $ref = XMLin( $path ) || die "can't open $path: $!";                  my $ref = XMLin( $path ) || die "can't open $path: $!";
28                  $page->{ $ref->{name} } = $ref->{widgets}->{widget}->{data};  
29                  warn dump( $ref->{widgets}->{widget}->{data} );                  my $name = $ref->{name} || die "no name in $path";
30    
31                    return if $name =~ m/^TamSystem/;
32    
33                    my $date =  $ref->{meta}->{LastModified};
34                    if ( ! $date ) {
35                            warn "SKIP: no LastModified in $path $name";
36                            return;
37                    }
38                    my $data =
39                            $ref->{widgets}->{widget}->{data} ||
40                            $ref->{widgets}->{widget}->{Body}->{data} ||
41                            die "no data in $path ",dump( $ref );
42    
43                    $page->{ $name } = [ $data, $date ];
44    
45                    #warn dump( $ref );
46          },          },
47  }, shift @ARGV || '.');  }, shift @ARGV || '.');
48    
49    my @pages = ( keys %$page );
50    
51  warn "found following pages: ", join(", ", keys %$page),"\n";  warn "found following pages: ", join(", ", @pages),"\n";
52    
53  my $Rester = Socialtext::Resting->new(  my $Rester = Socialtext::Resting->new(
54          username => 'tamtam',          username => 'tamtam',
# Line 49  sub surround { Line 73  sub surround {
73          return $with . $what . $with;          return $with . $what . $with;
74  }  }
75    
76    my $count = 0;
77    
78  foreach my $name ( keys %$page ) {  foreach my $name ( keys %$page ) {
79          my $body = $page->{$name} || die "no content for page $name";          last if $count++ == $max;
80    
81            my ( $body, $date ) = @{ $page->{$name} };
82            $date = time2str( $date );
83    
84          $body =~ s/\Q[[TableOfContents]]\E/{toc}/gs;          $body =~ s/\Q[[TableOfContents]]\E/{toc}/gs;
85          $body =~ s/\Q[[BR]]\E/\n/gs;          $body =~ s/\Q[[BR]]\E/\n/gs;
# Line 59  foreach my $name ( keys %$page ) { Line 88  foreach my $name ( keys %$page ) {
88          $body =~ s/'''(.+?)'''/surround('*',$1)/gse;          $body =~ s/'''(.+?)'''/surround('*',$1)/gse;
89          $body =~ s/''(.+?)''/surround('_',$1)/gse;          $body =~ s/''(.+?)''/surround('_',$1)/gse;
90    
91            # fix bullets
92            $body =~ s/^\s+([\*])/$1/gm;
93    
94            # fix links
95            $body =~ s/\["([^"]+)"\]/[$1]/gs;
96    
97          Encode::_utf8_off( $body );          Encode::_utf8_off( $body );
98    
99          $Rester->put_page( $name, $body );          my @tags = ( 'TamTam' );
         $Rester->put_pagetag( $name, 'TamTam' );  
100    
101            if ( $name =~ m!/! ) {
102                    my @page_tags = split(m!/!, $name);
103                    $name = pop @page_tags; # remove page name
104                    push @tags, @page_tags;
105            }
106    
107            $Rester->put_page( $name, {
108                    content => $body,
109                    date => $date,
110            });
111          print "+ $name\n";          print "+ $name\n";
112            foreach ( @tags ) {
113                    $Rester->put_pagetag( $name, $_ );
114                    print "+ $name [$_]\n";
115            }
116    
117  }  }
118    

Legend:
Removed from v.5  
changed lines
  Added in v.9

  ViewVC Help
Powered by ViewVC 1.1.26