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

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

  ViewVC Help
Powered by ViewVC 1.1.26