wiki.pl: Port some fixes from upstream
[Orgmuse.git] / merge-banned-lists
blobddcb0fb98aac0f01a0c3dc0f7588fec037df25ac
1 #!/usr/bin/perl -w
2 # merge-banned-list -- copy BannedContent from one wiki to another
3 # Copyright (C) 2004, 2005 Alex Schroeder <alex@emacswiki.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the
17 # Free Software Foundation, Inc.
18 # 59 Temple Place, Suite 330
19 # Boston, MA 02111-1307 USA
21 # This program copies the banned list from A to B, removing comments
22 # from A and keeping comments from B, and adding a date to entries
23 # that have none.
25 # $Id: merge-banned-lists,v 1.1 2006/04/26 23:36:29 as Exp $</p>'
27 use strict;
28 use LWP::UserAgent;
30 sub GetRaw {
31 my $uri = shift;
32 my $ua = LWP::UserAgent->new;
33 $ua->agent('Mozilla/5.0'); # some block libwww-perl
34 my $response = $ua->get($uri);
35 die $uri . ": " . $response->status_line . "\n" unless $response->is_success;
36 return $response->content;
39 sub Main {
40 my ($source, $target) = map {
41 $_ = GetRaw($_);
42 } @ARGV;
43 my ($sec, $min, $hour, $mday, $mon, $year) = gmtime();
44 my $date = sprintf('%4d-%02d-%02d', $year+1900, $mon+1, $mday);
45 my $result = join("\n", grep(/^(#|\s*$)/, split(/\n/, $target)));
46 $result .= "\n" . join("\n", map {
47 $_ .= " # $date" unless /#\s*\d\d\d\d-\d\d-\d\d/;
48 $_;
49 } sort(grep(/^[^#]/, split(/\n/, $source))));
50 print $result, "\n";
53 if ($#ARGV != 1 && $#ARGV != 2) {
54 die "Usage: $0 source-url target-url\n"
57 Main();