How to merge multiple opml files?

cross-posted from: https://discuss.tchncs.de/post/48831918

I have multiple .opml files (that list rss feeds I subscribe to in xml i.g.) with different contents on different devices. How can I merge them without duplicates? Are there tools for this?

4 points · 3 comments · view on lemmy.world

3 Comments

kevincox@lemmy.ml · 5 pts · 267d

The "dumb" solution is to just import both into one feed reader then export a new OPML. I assume most readers will deduplicate (at least to a basic degree) on import.

xsukax@lemmy.zip · 2 pts · 155d

If you're on Linux/macOS, a one-liner with xmllint or even plain Python handles this cleanly:

import xml.etree.ElementTree as ET

files = ["feeds1.opml", "feeds2.opml", "feeds3.opml"]
seen = set()
base = ET.parse(files[0]).getroot()
body = base.find("body")

for f in files[1:]:
    for outline in ET.parse(f).iter("outline"):
        url = outline.get("xmlUrl")
        if url and url not in seen:
            seen.add(url)
            body.append(outline)

# Seed the base with already-existing URLs
for o in ET.parse(files[0]).iter("outline"):
    seen.add(o.get("xmlUrl", ""))

ET.ElementTree(base).write("merged.opml")

Run it, done — deduplication is handled by xmlUrl.

PlanterTree@discuss.tchncs.de · 2 pts · 267d

update: https://www.opml.iadij.com/ seems to do exactly that.

github.com/imdj/opml-editor