#!/usr/bin/perl
# Time-stamp: "2024-11-14 05:15:26 MST"
#
# See http://www.interglacial.com/rss/ for info on RSS feeds
#

use strict;
use constant DEBUG => $ENV{'MAILTO'} ? 0 : 1;
#sub XML::RSS::SimpleGen::DEBUG () {6};
use utf8;

BEGIN {
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
 # That's all it takes to make all of LWP ignore certificate things.
}


use XML::RSS::SimpleGen 12;

DEBUG > 2 and print $_;

rss_new(
  (my $base =
	#"http://modis.gsfc.nasa.gov/gallery/showall.php",
      'https://modis.gsfc.nasa.gov/gallery/showall.php',
  ),
  "NASA MODIS Image of the Day",
  "Daily Images from the Moderate Resolution Imaging Spectroradiometer sensors on the NASA Earth Observing System satellites Terra and Aqua.",
);
rss_daily;
rss_language("en-US");
rss_webmaster('sburke@pobox.com');
my $nombre = 'nasa_modis_image_of_the_day';
rss_self_url(      "http://interglacial.com/rss/$nombre.rss" );
rss_generator_url( "http://interglacial.com/rss/$nombre.pl" );
rss_livejournal( 'nasa_modis' );

get_url( $base );

if( time() < 1519769140 ) {  # 2018-02-27
  rss_item("http://interglacial.com/rss/nasa_modis_image_of_the_day.rss#note_2018-02-16",
    "Message from the RSS Feedmaster- We're on a planet in outer space!!",
    "Message from the RSS Feedmaster:  Hello, INTERNETS.  This newsfeed for NASA MODIS pictures was broken since about November.  But now it's back!  Sorry for the bother and delay.  I now return you to your regularly scheduled pictures of Earth.",
  );
}

my $matcher_re =
qr≈
    (<img\s+src="http://modis\.gsfc\.nasa\.gov/gallery/images/image[^"<> ]+"\s+width="134"\s+height="102"\s+border="0">)</a>
    \s+<br>
    \s+<a\s+href="(http://modis\.gsfc\.nasa\.gov/gallery/individual\.php\?db_date=(\d\d\d\d-\d\d-\d\d))"><span\s+class="leftmenu-white">(.*?)</span></a>
    \s+
≈x; #"

my $matches = 0;
while(
  $_ =~ m/$matcher_re/g
) {
  my($img, $url, $date, $title) = ($1,$2,$3,$4);
  DEBUG and print ">> $date $title $url\n $img\n\n";
  rss_item( $url,              "0$date: $title",
    \rss_xmlesc( "<a href='$url'>0$date: $title</a><br><a href='$url'>$img</a>")
  );
  ++$matches;
}


#rss_item_count()
$matches
 or die "$0: No items in $base :\n{{\n$_\n}}\nAborted";

rss_save("$nombre.rss", 2);

DEBUG and print rss_as_string;
DEBUG and print "Found $matches matches.\n";

__END__
