#!/usr/bin/perl -W # # atom2rss.pl - A script which converts an Atom channel XML file to an RSS 2.0 XML file. # # Copyright (C) 2011-2021 Bogdan 'bogdro' Drozdowski, http://bogdro.evai.pl/soft/ # (bogdro /AT\ users . sourceforge . net) # # Licence: # GNU General Public Licence v3 # # Last modified : 2021-10-17 # # Syntax: # ./atom2rss.pl file_in.xml file_out.xml # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 3 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foudation: # Free Software Foundation # 51 Franklin Street, Fifth Floor # Boston, MA 02110-1301 # USA use warnings; use strict; my ($infname, $outfname, $entry, @month); my ($infile, $outfile); @month = ( '', 'Jan', 'Feb' , 'Mar' , 'Apr' , 'May', 'Jun' , 'Jul' , 'Aug' , 'Sep', 'Oct' , 'Nov' , 'Dec' ); if ( @ARGV == 0 || @ARGV == 1 ) { print "Syntax: $0 channel.in channel.out\n"; exit 1; } ########################################################## # opening the files if ( !open ( $infile, $ARGV[0] ) ) { # $! is the error message print "$0: $ARGV[0]: $!\n"; exit 2; } $outfname = $ARGV[1]; if ( !open ( $outfile, "> $outfname" ) ) { print "$0: $outfname: $!\n"; close $infile; exit 3; } ########################################################## # processing: while ( <$infile> ) { s#<\s*feed\s+xmlns\s*=.+>#\n#io; if ( /updated\s*>/io ) { s#<\s*updated\s*>(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z#$3 $month[$2] $1 $4:$5:$6 +0100#gi; } if ( /<\s*link/io && /rel\s*=/io ) { # Atom: # RSS2: # http://host //io; my $adr = $1; if ( $adr =~ /\.\w+$/o ) {$adr =~ s#/[^/]*$#/#o;} print $outfile "\t$adr\n"; $adr .= $outfname unless $adr =~ /#echo var='REQUEST_URI'/io; print $outfile "\n\t\n"; next; } next if /<\s*author/io; if ( /<\s*title\s*>(.*)<\s*\/\s*title\s*>/io && !$entry ) { print $outfile "$_\n\t$1\n"; next; } if ( /<\s*id>/io ) { if ( $entry ) {s#<\s*id>([^<]*)#$1#ig;} else {next;} } # a link should be an URL, not an ID s#<\s*link\s+href\s*=\s*"(.+)"\s*/\s*>#$1#ig; if ( /entry/io ) { s/entry\s*>/item>/gio; $entry = 1; } if ( /<\/entry>/io ) {$entry = 0;} s/summary\s*>/description>/igo; s#<\s*/\s*feed\s*>#\n#io; print $outfile $_; } ########################################################## # end close $outfile; close $infile;