67 lines
1.9 KiB
Perl
Executable File
67 lines
1.9 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
use v5.14;
|
|
|
|
use XML::RAI;
|
|
use XML::Atom::Client;
|
|
use DBI;
|
|
use CGI;
|
|
use Rss2Html::Scrubber;
|
|
use Time::HiRes qw(time);
|
|
use POSIX qw(strftime);
|
|
|
|
$| = 1;
|
|
|
|
my $q = CGI->new();
|
|
binmode STDOUT, ":encoding(UTF-8)";
|
|
|
|
my $feed_id = $q->param('id');
|
|
|
|
my $dbh = DBI->connect("dbi:SQLite:dbname=rss2html.sqlite", "", "");
|
|
$dbh->{sqlite_unicode} = 1;
|
|
|
|
print "Content-Type: text/html; charset=utf-8\n";
|
|
print "Refresh: 600\n";
|
|
print "\n";
|
|
|
|
print "<link rel='stylesheet' type='text/css' href='rss2html.css'/>\n";
|
|
print "<h1>RSS 2 HTML</h1>\n";
|
|
print "<p>", strftime("%Y-%m-%d %H:%M:%S%z", localtime()), "</p>\n";
|
|
|
|
my $feed = $dbh->selectrow_hashref("select * from feeds where id=?", {}, $feed_id);
|
|
|
|
print "<span class='feed_info'>\n";
|
|
print "<span class='feed_id'>", $q->escapeHTML($feed->{id}), "</span>\n";
|
|
print "<span class='feed_title'>", $q->escapeHTML($feed->{title}), "</span>\n";
|
|
print "<span class='feed_type'>", $q->escapeHTML($feed->{type}), "</span>\n";
|
|
print "</span>\n";
|
|
|
|
my $now = time();
|
|
my $seconds_per_week = 86400 * 7;
|
|
my $start = $now - 4 * $seconds_per_week;
|
|
my $items = $dbh->selectall_arrayref("select * from items where feed_id=? and issued >= ? order by issued",
|
|
{ Slice => {} },
|
|
$feed->{id}, $start,
|
|
);
|
|
for my $item (@$items) {
|
|
my $t = $item->{issued};
|
|
my $dt1 = $now - $t;
|
|
my $dt2 = $dt1 % $seconds_per_week;
|
|
$item->{dt2} = $dt2;
|
|
}
|
|
$items = [ sort { $a->{dt2} <=> $b->{dt2} } @$items ];
|
|
print "<table>\n";
|
|
for my $item (@$items) {
|
|
my $t = $now - $item->{dt2};
|
|
print"<tr>\n";
|
|
print"<td>", $item->{dt2}, "</td>\n";
|
|
print"<td>", strftime("%a %H:%M:%S", localtime($t)), "</td>\n";
|
|
print"<td>", "<a href='", $q->escapeHTML($item->{link}), "'>", $q->escapeHTML($item->{title}), "</a>", "</td>\n";
|
|
print"</tr>\n";
|
|
|
|
}
|
|
print "</table>\n";
|
|
# vim: expandtab
|