Skip to content

Instantly share code, notes, and snippets.

@credmp
Created May 12, 2017 10:55
Show Gist options
  • Save credmp/73fe8a327455899c891f9dfe2d96adcd to your computer and use it in GitHub Desktop.
Save credmp/73fe8a327455899c891f9dfe2d96adcd to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# Converts OPML to org-mode
# perl convert.pl file.opml > file.org
# Looking to convert the Feedly OMPL feed to something I can use with elfeed-org I ran across the code here: https://gist.github.com/alandipert/675767/aa45f49bf6f6a2038d0b77b24d0e079c0994edc5
#
# I modified it a little bit to be more to the point of elfeed-org
use XML::Parser;
binmode STDOUT, ":utf8";
$xp = new XML::Parser();
$xp->setHandlers(Start => \&start, End => \&end);
$xp->parsefile($ARGV[0]);
$indent = 0;
$tag = "";
sub start() {
my ($parser, $name, %attr) = @_;
if ($name eq "outline") {
for($i = 0; $i < $indent; $i++) { print "*"; }
# if ($indent > 0) { print " "};
if ($attr{xmlUrl}) {
print "* [[$attr{xmlUrl}][$attr{text}]] :$tag:\n";
} else {
$tag = lc($attr{text});
print "* $attr{text}\n";
}
$indent += 1;
}
}
sub end() {
my ($parser, $name) = @_;
if($name eq "outline") { $indent -= 1; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment