merge-banned-lists 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 2 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, write to the
  17. # Free Software Foundation, Inc.
  18. # 59 Temple Place, Suite 330
  19. # Boston, MA 02111-1307 USA
  20. # This program copies the banned list from A to B, removing comments
  21. # from A and keeping comments from B, and adding a date to entries
  22. # that have none.
  23. # $Id: merge-banned-lists,v 1.1 2006/04/26 23:36:29 as Exp $</p>'
  24. use strict;
  25. use LWP::UserAgent;
  26. sub GetRaw {
  27. my $uri = shift;
  28. my $ua = LWP::UserAgent->new;
  29. $ua->agent('Mozilla/5.0'); # some block libwww-perl
  30. my $response = $ua->get($uri);
  31. die $uri . ": " . $response->status_line . "\n" unless $response->is_success;
  32. return $response->content;
  33. }
  34. sub Main {
  35. my ($source, $target) = map {
  36. $_ = GetRaw($_);
  37. } @ARGV;
  38. my ($sec, $min, $hour, $mday, $mon, $year) = gmtime();
  39. my $date = sprintf('%4d-%02d-%02d', $year+1900, $mon+1, $mday);
  40. my $result = join("\n", grep(/^(#|\s*$)/, split(/\n/, $target)));
  41. $result .= "\n" . join("\n", map {
  42. $_ .= " # $date" unless /#\s*\d\d\d\d-\d\d-\d\d/;
  43. $_;
  44. } sort(grep(/^[^#]/, split(/\n/, $source))));
  45. print $result, "\n";
  46. }
  47. if ($#ARGV != 1 && $#ARGV != 2) {
  48. die "Usage: $0 source-url target-url\n"
  49. }
  50. Main();