In order to create my Blogroll automatically, I needed to convert the OPML export from Miniflux to markdown. While RSS-OPML-to-Markdown was a good start, I didn’t like the table output and the fact I couldn’t access htmlUrl
data attributes.
This python script outputs a tag-separated list of feeds, linked with that htmlUrl
rather than the rss feed itself. Passing tags to –ignore will omit them from the output.
pip3 install opml argparse
python ./opml_to_markdown.py --opmlFile ~/Downloads/feeds\(2\).opml --markdownFile blogroll.md --ignore All Private Newsletter
#
# opml_to_markdown.py
#
import opml
import argparse
def opml_to_markdown(opml_file, ignore_tags):
outline = opml.parse(opml_file)
markdown = ""
for tag in outline:
if tag.text in ignore_tags:
continue
markdown += "\n## {}\n\n".format(tag.text)
for feed in tag:
markdown += "* [{}]({})\n".format(feed.title, feed.htmlUrl)
return markdown
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--opmlFile', required=True)
parser.add_argument('--markdownFile', nargs='?')
parser.add_argument('--ignore', nargs='+')
args = parser.parse_args()
markdown = opml_to_markdown(args.opmlFile, args.ignore)
if args.markdownFile:
with open(args.markdownFile, 'wt', encoding="utf-8") as f:
f.write(markdown)
f.write("\n")
else:
print(markdown)