ell-to-wiki.pl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/perl
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2004 Alex Schroeder <alex@gnu.org>
  4. # Copyright (C) 2007 Vinicius José Latorre <viniciusjl at ig.com.br>
  5. #
  6. # This program is free software: you can redistribute it and/or modify it under
  7. # the terms of the GNU General Public License as published by the Free Software
  8. # Foundation, either version 3 of the License, or (at your option) any later
  9. # version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along with
  16. # this program. If not, see <http://www.gnu.org/licenses/>.
  17. use LWP::UserAgent;
  18. use XML::Parser;
  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. {
  27. package MySubs;
  28. my %index = {};
  29. sub StartTag {
  30. my ($e, $name) = @_;
  31. if ($name eq 'entry') {
  32. my $key = uc(substr($_{filename}, 0, 1));
  33. unless (exists $index{$key}) {
  34. $index{$key} = 1;
  35. print "= $key =\n\n";
  36. }
  37. print "[$_{site} $_{filename}] --- $_{description} (by $_{contact})\n\n";
  38. } elsif ($name eq 'date') {
  39. print "Timestamp: ";
  40. }
  41. }
  42. sub EndTag {
  43. my ($e, $name) = @_;
  44. if ($name eq 'date') {
  45. print "\nThis page is based on the EmacsLispList by StephenEglen and updated automatically.\n\n*Do not edit.*\n\n<toc/dense>\n\n";
  46. }
  47. }
  48. sub Text {
  49. print $_ if $_;
  50. }
  51. }
  52. sub parse {
  53. my $data = GetRaw('http://anc.ed.ac.uk/~stephen/emacs/ell.xml');
  54. my $parser = new XML::Parser(Style => 'Stream', Pkg => 'MySubs');
  55. binmode(STDOUT, ':utf8');
  56. $parser->parse($data);
  57. }
  58. parse();