Browse Source

use wget instead of built-in Perl LWP

improve handling of valid requests or parsing
attempts
closes #5
closes #7
closes #6
master
René Wagner 4 months ago
parent
commit
5a95a29735
  1. 1
      README.md
  2. 54
      orrg.pl

1
README.md

@ -40,3 +40,4 @@ Given this restrictions is not suitable for high traffic feeds which are updated
- DateTime::Format::ISO8601
- HTML::Strip
- Python 3 for `gcat`
- wget

54
orrg.pl

@ -38,21 +38,28 @@ sub create_response
my ( $qs ) = @_;
my @body = ();
my $feed = feed_get($qs);
if ( !defined($feed) ) {
my $content = feed_get($qs);
if ( !defined($content) || $content eq '' ) {
push @body, ('# orrg error', '', 'The requested feed could not be loaded. :(', '', '=> '. $qs .' open feed in browser');
return @body;
} else {
my $feed = feed_parse($content);
if (defined($feed)) {
recent_add($qs, trim_ws($feed->title));
popular_add($qs, trim_ws($feed->title));
push @body, '# '. trim_ws($feed->title);
push @body, 'fetched '. strftime('%Y-%m-%dT%H:%M:%SZ', gmtime());
push @body, '';
$feed->description eq '' or push @body, trim_ws($feed->description);
$feed->image eq '' or push @body, '=> '. $feed->image .' feed image';
$feed->link eq '' or push @body, ('=> '.$feed->link.' open website', '');
foreach my $it ($feed->get_item()) { push @body, @{item($it)}; }
} else {
push @body, ('# orrg error', '', 'The requested feed could be loaded but not parsed. :(', '', '=> '. $qs .' open feed in native client');
}
}
push @body, '# '. trim_ws($feed->title);
push @body, 'fetched '. strftime('%Y-%m-%dT%H:%M:%SZ', gmtime());
push @body, '';
$feed->description eq '' or push @body, trim_ws($feed->description);
$feed->image eq '' or push @body, '=> '. $feed->image .' feed image';
$feed->link eq '' or push @body, ('=> '.$feed->link.' open website', '');
foreach my $it ($feed->get_item()) { push @body, @{item($it)}; }
push @body, ('', '', '=> ./index.pl [home]');
return @body;
}
@ -101,17 +108,22 @@ sub feed_get
{
my ( $query ) = @_;
my $feed;
if ( $query =~ /^https\:\/\// ) { $feed = XML::FeedPP->new($query, utf8_flag => 1); }
my $content;
if ( $query =~ /^https\:\/\// ) { $content = `wget -qO - $query`; }
if ( $query =~ /^gemini\:\/\// ) {
my $content = `./gcat $query`;
$content = `./gcat $query`;
$content =~ /20\W/ or return undef;
$content =~ s/^[0-9]{0,2}\W.+\r\n//;
$feed = XML::FeedPP->new($content, -type => 'string', utf8_flag => 1);
}
recent_add($query, $feed->title);
popular_add($query, $feed->title);
$feed->sort_item();
return $content;
}
sub feed_parse
{
my ($content) = @_;
my $feed = XML::FeedPP->new($content, -type => 'string', utf8_flag => 1);
if (defined($feed)) { $feed->sort_item(); }
return $feed;
}
Loading…
Cancel
Save