[Privoxy-users] RSS feed script

Unknown arkmail0 at riseup.net
Wed Jun 29 00:47:27 UTC 2016


- Tested on latest Strawberry Perl.
- Config lines from START to END before using.
- HTH.
-------------- next part --------------
#!/usr/local/bin/perl
#< License = WTFPL >
use Digest::SHA1;
@months=qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);@days=qw(Sun Mon Tue Wed Thu Fri Sat Sun);

#< Config START >
$scan_dir='/select/path/to/sf-download/';
$base_dlurl='https://www.privoxy.org/sf-download-mirror/';
$save_rss_file='/select/where/to/save/release.xml';
$maxlimit=10;
#< Config END >

my @Array=();$i=0;
opendir (D1,$scan_dir) or die 'error1';MOUT: while (my $fi1=readdir(D1)){next if ($fi1 =~ m/^\./);
opendir (D2,$scan_dir.$fi1.'/') or die 'error2';while (my $fi2=readdir(D2)){next if ($fi2 =~ m/^\./);
opendir (D3,$scan_dir.$fi1.'/'.$fi2.'/') or die 'error3';while (my $fi3=readdir(D3)){next if ($fi3 =~ m/^\./);
$target=$scan_dir.$fi1.'/'.$fi2.'/'.$fi3;next if (! -e $target);
my $filedata;unless (open $filedata,$target){next;}
my $sha1 = Digest::SHA1->new;$sha1->addfile($filedata);close $filedata;
$target_sha1=$sha1->hexdigest;
$target_uri=$fi1.'/'.$fi2.'/'.$fi3;
$target_time=(stat $target)[9];
$target_line='<item><title><![CDATA['.$target_uri.']]></title>';
$target_line.='<description><![CDATA['.$target_uri.' (SHA-1: '.$target_sha1.')]]></description>';
$target_line.='<link>'.$base_dlurl.$target_uri.'</link><guid>'.$base_dlurl.$target_uri.'</guid>';
$target_line.='<pubDate>';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime($target_time);$target_line.="$days[$wday], $mday $months[$mon] ".($year+1900)." $hour:$min:$sec GMT";
$target_line.='</pubDate></item>';
$Array[$i]=([$target_time,$target_line]);$i++;
if ($i>=$maxlimit){last MOUT;}
}
closedir D3;
}
closedir D2;
}
closedir D1;
$result='<?xml version="1.0" encoding="utf-8"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel><title>Privoxy Releases</title><link>https://www.privoxy.org/announce.txt</link><description><![CDATA[Privoxy Releases RSS feed]]></description><pubDate>';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=gmtime();$result.="$days[$wday], $mday $months[$mon] ".($year+1900)." $hour:$min:$sec GMT";
$result.='</pubDate>';
my @resArray=sort {@$a[0]<=>@$b[0]} @Array;$i--;
while($i>=0){$result.=$resArray[$i][1];$i--;}
$result.='</channel></rss>';
open(XMLF,"> $save_rss_file") or die 'write error';
print XMLF $result;
close(XMLF);


More information about the Privoxy-users mailing list