moin-search.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #! /usr/bin/perl
  2. # Copyright (C) 2003 Alex Schroeder <alex@emacswiki.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. use CGI qw/:standard/;
  17. use CGI::Carp qw(fatalsToBrowser);
  18. use LWP::UserAgent;
  19. if (not param('url')) {
  20. print header(),
  21. start_html('MoinMoin Search RSS 3.0'),
  22. h1('MoinMoin Search RSS 3.0'),
  23. p('Translates a MoinMoin Search result into RSS 3.0 usable by Oddmuse.'),
  24. start_form(-method=>'GET'),
  25. p('Search URL: ', textfield('url'), submit()),
  26. end_form(),
  27. end_html();
  28. exit;
  29. }
  30. print header(-type=>'text/plain; charset=UTF-8');
  31. my $ua = new LWP::UserAgent;
  32. my $request = HTTP::Request->new('GET', param('url'));
  33. my $response = $ua->request($request);
  34. my $data = $response->content;
  35. $data =~ /\<title\>([^<]*)/i;
  36. print "title: $1\n" if $1;
  37. print "link: " . param('url') . "\n\n";
  38. $data =~ /\<ul\>((.*\n)*.*)\<\/ul\>/i;
  39. foreach $item (split(/\<li\>/i, $1)) {
  40. next unless $item =~ /\<a[^>]*\>([^<]+)/i;
  41. print "title: $1\n";
  42. $desc = '';
  43. while ($item =~ m/\<font[^>]*\>((.*?\n)*?.*?)\<\/font\>/gi) {
  44. $word = $1;
  45. $word =~ s/^\.\.\.\S+/\.\.\./;
  46. $word =~ s/\S+\.\.\.$/\.\.\./;
  47. $desc .= $word . ' ';
  48. }
  49. if ($desc) {
  50. $desc =~ s/\<\/?b\>//gi;
  51. $desc =~ s/[\r\n\t]+/ /g;
  52. $desc =~ s/\.\.\. \.\.\./\.\.\./g;
  53. print "description: $desc\n";
  54. }
  55. print "\n";
  56. }