Sorry

This feed does not validate.

Source: http://www.kerryandjane.com/cgi-bin/news.xml

  1. #!/usr/bin/perl -wT
  2.  
  3. use lib ".";
  4. use Kerryandjane;
  5. use strict;
  6.  
  7. my %sections = ();
  8.  
  9. print "Content-type: text/xml\n\n";
  10.  
  11. print <<'EOF';
  12. <?xml version="1.0" encoding="utf-8"?>
  13. <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  14. xmlns="http://purl.org/rss/1.0/">
  15.    <channel rdf:about="http://www.kerryandjane.com/cgi-bin/news.xml">
  16. <title>Kerry and Jane's News</title>
  17. <description>
  18.    Tedious and rarely-updated news from Kerry and Jane.
  19. </description>
  20. <link>http://www.kerryandjane.com</link>
  21. <items>
  22.    <rdf:Seq>
  23. EOF
  24.  
  25. # first get a list of valid sections
  26. open (LIST, "<", "../data/sections.dat") or die ("Failed to open section list: $!");
  27. while (<LIST>) {
  28.    next if /^\s*#/;
  29.    if (/^(.*?),(.*)$/) {
  30. $sections {$1} = $2;
  31.    }
  32. }
  33. close LIST;
  34.  
  35. my %files = ();
  36. my $date = "";
  37.  
  38. foreach my $section (sort keys %sections) {
  39.    while (<../data/$section/news/*xml>) {
  40. if (-r) {
  41.    my $filename = $_;
  42.    $date = get_date ($_);
  43.    if ($date) {
  44. if ($files {"$date"}) {
  45.    my $temp_date = $date;
  46.    for (my $count = 1; $files {"$temp_date"}; $count++) {
  47. $temp_date = sprintf ("%s-%02d", $date, $count);
  48.    }
  49.    $date = $temp_date;
  50. }
  51. $files {"$date"} = $filename;
  52.    }
  53. }
  54.    }
  55. }
  56.  
  57. my $last_file = (keys (%files) < 5 ? keys (%files) - 1 : 4);
  58.  
  59. foreach ((reverse sort keys %files) [0..$last_file]) {
  60.    parse ($files {$_}, "ref");
  61. }
  62.  
  63. print << "EOF";
  64.    </rdf:Seq>
  65. </items>
  66.    </channel>
  67.    <image rdf:about=\"$Kerryandjane::img_loc/kerryandjane88x31.gif\">
  68. <title>Kerry and Jane's Page</title>
  69. <url>$Kerryandjane::img_loc/kerryandjane88x31.gif</url>
  70. <link>http://www.kerryandjane.com</link>
  71.    </image>
  72. EOF
  73.  
  74. foreach ((reverse sort keys %files) [0..$last_file]) {
  75.    parse ($files {$_}, "item");
  76. }
  77.  
  78. print "</rdf:RDF>\n";
  79.  
  80. sub get_date {
  81.    my ($filename) = @_;
  82.    my $year = 0;
  83.    my $month = 0;
  84.    my $date = 0;
  85.    if (-r $filename) {
  86. local $/;
  87. open (ARTICLE, "<", "$filename") or return "00000000";
  88. my $contents = <ARTICLE>;
  89. close ARTICLE;
  90. if ($contents =~ m|<DATE.*YEAR="(\d+)"|is) {
  91.    $year = sprintf ("%04d", $1);
  92. }
  93. if ($contents =~ m|<DATE.*MONTH="(\d+)"|is) {
  94.    $month = sprintf ("%02d", $1);
  95. }
  96. if ($contents =~ m|<DATE.*DATE="(\d+)"|is) {
  97.    $date = sprintf ("%02d", $1);
  98. }
  99.    }
  100.    return "$year$month$date";
  101. }
  102.  
  103. sub parse {
  104.    my ($filename) = $_[0];
  105.    my ($mode) = $_[1];
  106.  
  107.    $filename =~ m|.*/(.*?)/news/(.*?)$|;
  108.    my $section = $1;
  109.    my $file = $2;
  110.    my $title = "[No Title]";
  111.    my $year = 0;
  112.    my $month = 0;
  113.    my $date = 0;
  114.    my $body = "";
  115.    if (-r $filename) {
  116. local $/;
  117. open (ARTICLE, "<", "$filename") or die ("Failed to open $filename: $!");
  118. my $contents = <ARTICLE>;
  119. close ARTICLE;
  120. if ($contents =~ m|<TITLE\b.*?VALUE="(.+?)".*?>|is) {
  121.    $title = $1;
  122. }
  123. if ($contents =~ m|<DATE\b.*YEAR="(\d+)"|is) {
  124.    $year = $1;
  125. }
  126. if ($contents =~ m|<DATE\b.*MONTH="(\d+)"|is) {
  127.    $month = $1
  128. }
  129. if ($contents =~ m|<DATE\b.*DATE="(\d+)"|is) {
  130.    $date = $1;
  131. }
  132.  
  133. if ($mode eq "ref") {
  134.    print "            <rdf:li rdf:resource=\"http://www.kerryandjane.com/index.shtml\?section=$section\&amp;filename=$file\"/>\n";
  135. } else {
  136.    $contents =~ m|<body>(.*?)</body>|is;
  137.    $body = $1;
  138.    # only show the first paragraph
  139.    $body =~ s/<p>.*//is;
  140.    # remove cross-reference tags
  141.    $body =~ s|<xref text="(.?)".?/>|$1|is;
  142.    print << "EOF";
  143.    <item rdf:about="http://www.kerryandjane.com/index.shtml\?section=$section\&amp;filename=$file\">
  144. <title>$title ($date/$month/$year)</title>
  145. <link>http://www.kerryandjane.com/index.shtml\?section=$section\&amp;filename=$file</link>
  146. <description>$body</description>
  147.    </item>
  148. EOF
  149. }
  150.    }
  151. }
  152.  
Copyright © 2002-9 Sam Ruby, Mark Pilgrim, Joseph Walton, and Phil Ringnalda