opml to html, or, I know you're not supposed to use regexes but fuck it

2019-11-06-1 #1

I tried to do it the right way. I tried all the xml manipulation libraries. But they all failed. Or I failed them. Either way it was just faster and far easier to do it with regex than attempt to learn some new xml module. So here is the dirty result that makes /feeds.html on my site from the opml that QuiteRSS spits out.

#!/usr/bin/perl -w
# Usage: regexopmltohtml.pl foo.opml > bar.html
use strict;
my $opmlfiletoparse = shift;
open( THEFILE, "<$opmlfiletoparse") or die "Can't open file $opmlfiletoparse $!";
while(<THEFILE>) {
	if ( m{<outline text=\"(.+)\">\n}sg) {
		my $name = $1;
		print qq[<hr />];
		print qq[<h3>$name</h3>];
	} elsif ( m{<outline text=\"(.+)\" type=\".+?\" htmlUrl=\"(.+)?\" xmlUrl=\"(.+)\"/>}sg) {
		#print "1: $1, 2: $2, 3: $3\n" if $1;
		my($name,$htmlurl,$xmlurl) = ($1,$2,$3);
		print qq[<p>];
		print qq[<a href="$xmlurl"><img src="/rss.png" border="0" /></a>\n];
		print qq[<a href="$htmlurl">$name</a></p>];