this ads an error log into the RSS feed loop, logging which URLs fail parsing
This commit is contained in:
parent
d30f85b57b
commit
889aae9f6a
25
smhnRSS.pl
25
smhnRSS.pl
@ -28,10 +28,12 @@ use HTML::Entities; # https://metacpan.org/pod/HTML::Entities
|
||||
# server file folders
|
||||
# my $rssFilePath = "/home/USER_FOLDER/public_html/feed.xml";
|
||||
# my $htmlFilePath = "/home/USER_FOLDER/public_html/index.html";
|
||||
# my $errorFilePath = "/home/USER_FOLDER/public_html/feed.log";
|
||||
|
||||
# local file folders
|
||||
my $rssFilePath = "feed.xml";
|
||||
my $htmlFilePath = "index.html";
|
||||
my $errorFilePath = "feed.log";
|
||||
|
||||
###################################
|
||||
# RSS Configurations
|
||||
@ -63,6 +65,9 @@ my %list;
|
||||
# Make the list of URLS while parsing DATA
|
||||
my $listHTML = "<div class=\'listHTML\'><ul>\n";
|
||||
|
||||
# Make a list of URLs that have an error
|
||||
my $listURLError = "The following feeds had issues this time:\n\n" . $now->strftime('%a, %d %b %Y %H:%M:%S %z'). "\n\n";
|
||||
|
||||
# Go through each URL in the DATA section and make the new list
|
||||
while ( my $url = <DATA>) {
|
||||
chomp $url;
|
||||
@ -76,7 +81,12 @@ while ( my $url = <DATA>) {
|
||||
# parse the XML
|
||||
my $rss1 = XML::RSS->new;
|
||||
eval { $rss1->parse( $xml ) };
|
||||
next if $@;
|
||||
|
||||
# if empty, add URL to log file variable
|
||||
if ($@) {
|
||||
$listURLError .= "* " . $url . "\n";
|
||||
next;
|
||||
}; # if $@
|
||||
|
||||
# go through the items from the XML
|
||||
for (my $j = 0; $j <= $number_of_items; $j++){
|
||||
@ -138,6 +148,14 @@ while ( my $url = <DATA>) {
|
||||
#close out the list URL html
|
||||
$listHTML .= "</ul></div>\n";
|
||||
|
||||
###################################
|
||||
# Write the error file
|
||||
###################################
|
||||
|
||||
open(FH, '>', $errorFilePath) or die $!;
|
||||
print FH $listURLError;
|
||||
close(FH);
|
||||
|
||||
###################################
|
||||
# Make an RSS Feed!
|
||||
###################################
|
||||
@ -204,6 +222,9 @@ my $printDate = formatDate($rss2->{'channel'}{'pubDate'});
|
||||
# header for a direct HTML post
|
||||
my $html_header = "Status: 200\nContent-type: text/html\n\n";
|
||||
|
||||
|
||||
|
||||
|
||||
###################################
|
||||
# Make the HTML Page
|
||||
###################################
|
||||
@ -335,6 +356,7 @@ sub formatDate {
|
||||
|
||||
__DATA__
|
||||
https://ecatherine.com/feed/
|
||||
https://lynnehansen.zenfolio.com/blog.rss
|
||||
https://redlagoe.com/feed/
|
||||
https://diebooth.wordpress.com/feed/
|
||||
https://kelliowen.com/feed/
|
||||
@ -362,6 +384,5 @@ http://robertfordauthor.com/feed/
|
||||
https://tinyfrights.com/feed/
|
||||
https://weightlessbooks.com/feed/
|
||||
https://www.crystallakepub.com/feed/
|
||||
https://lynnehansen.zenfolio.com/blog.rss
|
||||
https://www.bevvincent.com/feed/
|
||||
http://liviallewellyn.com/feed/
|
Loading…
x
Reference in New Issue
Block a user