#!/usr/bin/perl
# use cPanelUserConfig; #for cpanel servers
use 5.010;
use strict;
use warnings;
###################################
#
# The Sunday Morning Horror News
#
# This script pulls from a list of RSS feeds and agregates them together into a web page.
# It is designed to run as a cron and overright the HTML file.
#
# license GPLv3.0 https://www.gnu.org/licenses/gpl-3.0.en.html
# Code repository: https://code.jacobhaddon.com/jake/smhn
# Written by Jacob Haddon https://jacobhaddon.com
#
###################################
# Packages
use Time::Piece; # https://perldoc.perl.org/Time::Piece
use LWP::Simple; # https://metacpan.org/pod/LWP::Simple
use XML::RSS; # https://metacpan.org/pod/XML::RSS
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";
# local file folders
my $rssFilePath = "feed.xml";
my $htmlFilePath = "index.html";
###################################
# RSS Configurations
###################################
my $title = "Sunday Morning Horror News";
my $homeLink = "http://sundaymorninghorrornews.com";
my $feedLink = "http://sundaymorninghorrornews.com/feed.xml";
my $description = 'A collection of horror writer, editor, poet and publisher blogs from all over the web!';
my $webmaster = 'webmaster@sundaymorninghorrornews.com';
my $copyright = 'Copyright respective writers';
###################################
# Go through list of URLs, get RSS feed,
# take newest 3 that are less than $then old,
# add to new RSS feed object
###################################
# get today, subtact time to make cut off
my $now = localtime;
my $then = $now->add_months(-2);
#number of items to keep from each feed
my $number_of_items = 2; # +1 since everything starts at 0
#list to hold the new RSS items
my %list;
# Make the list of URLS while parsing DATA
my $listHTML = "
\n\n";
} # foreach item
# close out the rssHTML
$rssHTML .= "
\n\n";
# the webpage HTML
# format the pubDate
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
###################################
my $html = <<"HTML_END";
The Sunday Morning Horror News
$title
$description
This site is in BETA and will update daily as we test things out and add URLs. Let us know if there are sites that should be included!
updated: $printDate
The News!
$rssHTML
About $title
The $title is an aggregator of RSS feeds from writers, poets and publishers.
Too often the world is flying by at the speed of social media. $title is designed to update just once a week (on Sunday!) so you can take your time and catch up on the news without having to scroll.
Contact
Contact $title at: $webmaster
We are intolerant of intolerance. If you see something hateful, transphobic, homophobic, racist, or the like, let us know.
We don't publish the content you see here, just collect it, but we don't need to collect trash.
The List!
This is the list of the feeds that we are checking. If you have an RSS reader, grab them and follow along!
$listHTML
HTML_END
# write the file
open(FH, '>', $htmlFilePath) or die $!;
print FH $html;
close(FH);
# print $html_header . $html;
###################################
# Functions
###################################
sub formatDate {
# takes a date, and converts it to a formatted string
my $testDate = $_[0];
$testDate =~ s/((\+|\-)(\d\d\d\d))//;
# Convert to a TIME object
my $t = Time::Piece->strptime($testDate);
return($t->strftime('%a, %d %b %Y %H:%M:%S'));
} # sub formatDate
# FIN
###################################
# DATA is list of the feed URLs
###################################
__DATA__
https://ecatherine.com/feed/
https://redlagoe.com/feed/
https://diebooth.wordpress.com/feed/
https://kelliowen.com/feed/
https://mercedesmyardley.com/feed/
https://mehitobel.com/feed/
http://antoncancre.blogspot.com/feeds/posts/default?alt=rss
https://marysangi.wordpress.com/feed/
https://www.toddkeisling.com/news?format=rss
https://www.jfgonzalez.org/news?format=rss
https://www.briankeene.com/news?format=rss
https://www.cemeterydance.com/extras/feed/
https://www.gwendolynkiste.com/Blog/feed/
https://katherinesilvaauthor.substack.com/feed
https://queenofswordspress.com/feed/
http://fiendlover.blogspot.com/feeds/posts/default
http://jacobhaddon.com/feed/
http://apokrupha.com/feed/
https://ellendatlow.com/feed/
https://paulaguran.com/
https://amandaheadlee.com/feed/
https://theimbloglio.wordpress.com/feed/
https://kennethwcain.com/feed/
https://wellwortharead.blogspot.com/feeds/posts/default?alt=rss
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/