merge-list 1.9 KB

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