merge-banned-lists 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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>
  4. #
  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 3 of the License, or
  8. # (at your option) any later version.
  9. #
  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.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. # This program copies the banned list from A to B, removing comments
  18. # from A and keeping comments from B, and adding a date to entries
  19. # that have none.
  20. # $Id: merge-banned-lists,v 1.1 2006/04/26 23:36:29 as Exp $</p>'
  21. use strict;
  22. use LWP::UserAgent;
  23. sub GetRaw {
  24. my $uri = shift;
  25. my $ua = LWP::UserAgent->new;
  26. $ua->agent('Mozilla/5.0'); # some block libwww-perl
  27. my $response = $ua->get($uri);
  28. die $uri . ": " . $response->status_line . "\n" unless $response->is_success;
  29. return $response->content;
  30. }
  31. sub Main {
  32. my ($source, $target) = map {
  33. $_ = GetRaw($_);
  34. } @ARGV;
  35. my ($sec, $min, $hour, $mday, $mon, $year) = gmtime();
  36. my $date = sprintf('%4d-%02d-%02d', $year+1900, $mon+1, $mday);
  37. my $result = join("\n", grep(/^(#|\s*$)/, split(/\n/, $target)));
  38. $result .= "\n" . join("\n", map {
  39. $_ .= " # $date" unless /#\s*\d\d\d\d-\d\d-\d\d/;
  40. $_;
  41. } sort(grep(/^[^#]/, split(/\n/, $source))));
  42. print $result, "\n";
  43. }
  44. if ($#ARGV != 1 && $#ARGV != 2) {
  45. die "Usage: $0 source-url target-url\n"
  46. }
  47. Main();