Files
oddmuse/scripts/merge-banned-lists
Alex Schroeder 5e2d20ecdb Moved many files to scripts or contrib
These files were cluttering up the root directory.
2015-04-02 22:54:48 +02:00

58 lines
1.9 KiB
Perl

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