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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26