Bookmarked Blogroll by Dan MacKinlay (danmackinlay.name)

Make your own automatic blogroll

This is the script I use to generate a blogroll from my OPML:

#! /usr/bin/env python3
"""
Parse OPML into markdown.
"""
import sys
import re
from xml.etree import ElementTree

def main(fname):
with open(fname, 'r', encoding='utf8') as fp:
tree = ElementTree.parse(fp)
for cat_node in tree.find('body').findall('outline'):
print("\n## {}\n".format(cat_node.get('title')))
for node in cat_node.findall('outline'):
name = node.attrib.get('text')
feedurl = node.attrib.get('xmlUrl')
url = node.attrib.get('htmlUrl')
print("* [{}]({}) ([feed]({}))".format(name, url, feedurl))

if __name__ == "__main__":
main(*sys.argv[1:])
❧