merge-list 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/perl -w
  2. # merge-list -- merge BannedContent from two wikis
  3. # Copyright (C) 2004 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. use strict;
  18. use LWP::UserAgent;
  19. sub GetRaw {
  20. my $uri = shift;
  21. my $ua = LWP::UserAgent->new;
  22. my $request = HTTP::Request->new('GET', $uri);
  23. my $response = $ua->request($request);
  24. return $response->content;
  25. }
  26. sub Main {
  27. my ($source, $target, $forgiven) = map {GetRaw($_)} @ARGV;
  28. my (%source, %target);
  29. map {$source{$_} = 1} grep(/^[ \t]/, split(/\n/, $source));
  30. map {$target{$_} = 1} grep(/^[ \t]/, split(/\n/, $target));
  31. # remove all the links that are forgiven...
  32. foreach $_ (grep(/^[ \t]/, split(/\n/, $forgiven))) {
  33. delete $source{$_};
  34. delete $target{$_};
  35. }
  36. # merge the source lines to the target lines
  37. foreach $_ (keys %source) {
  38. $target{$_} = 1;
  39. }
  40. # now produce an updated pages from all the normal lines plus the
  41. # new target lines.
  42. my @page = grep(/^[^ \t]|$/, split(/\n/, $target));
  43. push(@page, "") unless $page[$#page] eq ''; # add empty line if required
  44. push(@page, sort(keys %target));
  45. print join("\n", @page);
  46. }
  47. if ($#ARGV != 2) {
  48. die "Usage: $0 source-url target-url forgiven-url\n";
  49. }
  50. Main();