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

Contents of /tamtam/tamtam2socialtext.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6 - (show annotations)
Wed Dec 12 12:48:42 2007 UTC (16 years, 3 months ago) by dpavlin
File MIME type: text/plain
File size: 2244 byte(s)
- add tags for all levels of page hierarchy
- try to add dates (broken for now)
1 #!/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 use HTTP::Date;
12 use Data::Dump qw/dump/;
13
14 my $max = 2;
15
16 my $page;
17 my $page_date;
18
19 find({
20 wanted => sub {
21 my $path = $File::Find::name;
22 return unless -f $path;
23
24 warn "# $path\n";
25 my $ref = XMLin( $path ) || die "can't open $path: $!";
26
27 my $name = $ref->{name} || die "no name in $path";
28 my $date = $ref->{meta}->{LastModified};
29 if ( ! $date ) {
30 warn "SKIP: no LastModified in $path $name";
31 return;
32 }
33 my $data =
34 $ref->{widgets}->{widget}->{data} ||
35 $ref->{widgets}->{widget}->{Body}->{data} ||
36 die "no data in $path ",dump( $ref );
37
38 $page->{ $name } = [ $data, $date ];
39
40 #warn dump( $ref );
41 },
42 }, shift @ARGV || '.');
43
44 my @pages = ( keys %$page );
45
46 warn "found following pages: ", join(", ", @pages),"\n";
47
48 my $Rester = Socialtext::Resting->new(
49 username => 'tamtam',
50 password => 'import',
51 server => 'http://saturn.ffzg.hr/',
52 );
53 $Rester->workspace('razmjenavjestina');
54 $Rester->put_workspacetag('TamTam');
55
56 sub header {
57 my $h = shift;
58 if ( $h =~ m/^(=+)\s+(.+?)\s+\1$/ ) {
59 my $level = length($1);
60 return "\n" . ( '^' x $level ) . " $2\n";
61 } else {
62 die "can't parse header: $h";
63 }
64 }
65
66 sub surround {
67 my ( $with, $what ) = @_;
68 return $with . $what . $with;
69 }
70
71 my $count = 0;
72
73 foreach my $name ( keys %$page ) {
74 last if $count++ == $max;
75
76 my ( $body, $date ) = @{ $page->{$name} };
77 $date = time2str( $date );
78
79 $body =~ s/\Q[[TableOfContents]]\E/{toc}/gs;
80 $body =~ s/\Q[[BR]]\E/\n/gs;
81 $body =~ s/$RE{balanced}{-begin => "= |== |=== |==== |===== |===== "}{-end => " =| ==| ===| ====| ====="}{-keep}/header($1)/gse;
82 $body =~ s/''''(.+?)''''/surround('`',$1)/gse;
83 $body =~ s/'''(.+?)'''/surround('*',$1)/gse;
84 $body =~ s/''(.+?)''/surround('_',$1)/gse;
85
86 Encode::_utf8_off( $body );
87
88 my @tags = ( 'TamTam' );
89
90 if ( $name =~ m!/! ) {
91 my @page_tags = split(m!/!, $name);
92 pop @page_tags; # remove page name
93 push @tags, @page_tags;
94 $name =~ s!/!_!g;
95 }
96
97 $Rester->put_page( $name, {
98 content => $body,
99 date => $date,
100 });
101 print "+ $name\n";
102 foreach ( @tags ) {
103 $Rester->put_pagetag( $name, $_ );
104 print "+ $name [$_]\n";
105 }
106
107 }
108

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26