/[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

Annotation of /tamtam/tamtam2socialtext.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations)
Wed Dec 12 13:17:15 2007 UTC (16 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 2301 byte(s)
- skip system pages
- use correct page names (last component of path)
1 dpavlin 5 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     use XML::Simple;
7     use File::Find;
8     use Regexp::Common qw/balanced/;
9     use Socialtext::Resting;
10     use Encode;
11 dpavlin 6 use HTTP::Date;
12 dpavlin 5 use Data::Dump qw/dump/;
13    
14 dpavlin 8 my $max = 5;
15 dpavlin 6
16 dpavlin 5 my $page;
17 dpavlin 6 my $page_date;
18 dpavlin 5
19     find({
20     wanted => sub {
21     my $path = $File::Find::name;
22     return unless -f $path;
23 dpavlin 6
24 dpavlin 5 warn "# $path\n";
25     my $ref = XMLin( $path ) || die "can't open $path: $!";
26 dpavlin 6
27     my $name = $ref->{name} || die "no name in $path";
28 dpavlin 8
29     return if $name =~ m/^TamSystem/;
30    
31 dpavlin 6 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 dpavlin 5 },
45     }, shift @ARGV || '.');
46    
47 dpavlin 6 my @pages = ( keys %$page );
48 dpavlin 5
49 dpavlin 6 warn "found following pages: ", join(", ", @pages),"\n";
50 dpavlin 5
51     my $Rester = Socialtext::Resting->new(
52     username => 'tamtam',
53     password => 'import',
54     server => 'http://saturn.ffzg.hr/',
55     );
56     $Rester->workspace('razmjenavjestina');
57     $Rester->put_workspacetag('TamTam');
58    
59     sub header {
60     my $h = shift;
61     if ( $h =~ m/^(=+)\s+(.+?)\s+\1$/ ) {
62     my $level = length($1);
63     return "\n" . ( '^' x $level ) . " $2\n";
64     } else {
65     die "can't parse header: $h";
66     }
67     }
68    
69     sub surround {
70     my ( $with, $what ) = @_;
71     return $with . $what . $with;
72     }
73    
74 dpavlin 6 my $count = 0;
75    
76 dpavlin 5 foreach my $name ( keys %$page ) {
77 dpavlin 6 last if $count++ == $max;
78 dpavlin 5
79 dpavlin 6 my ( $body, $date ) = @{ $page->{$name} };
80     $date = time2str( $date );
81    
82 dpavlin 5 $body =~ s/\Q[[TableOfContents]]\E/{toc}/gs;
83     $body =~ s/\Q[[BR]]\E/\n/gs;
84     $body =~ s/$RE{balanced}{-begin => "= |== |=== |==== |===== |===== "}{-end => " =| ==| ===| ====| ====="}{-keep}/header($1)/gse;
85     $body =~ s/''''(.+?)''''/surround('`',$1)/gse;
86     $body =~ s/'''(.+?)'''/surround('*',$1)/gse;
87     $body =~ s/''(.+?)''/surround('_',$1)/gse;
88    
89 dpavlin 7 $body =~ s/^\s+([\*])/$1/gm;
90    
91 dpavlin 5 Encode::_utf8_off( $body );
92    
93 dpavlin 6 my @tags = ( 'TamTam' );
94 dpavlin 5
95 dpavlin 6 if ( $name =~ m!/! ) {
96     my @page_tags = split(m!/!, $name);
97 dpavlin 8 $name = pop @page_tags; # remove page name
98 dpavlin 6 push @tags, @page_tags;
99     }
100    
101     $Rester->put_page( $name, {
102     content => $body,
103     date => $date,
104     });
105 dpavlin 5 print "+ $name\n";
106 dpavlin 6 foreach ( @tags ) {
107     $Rester->put_pagetag( $name, $_ );
108     print "+ $name [$_]\n";
109     }
110    
111 dpavlin 5 }
112    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26