Last active
October 13, 2019 02:18
-
-
Save mhart/96dad3689cccc04a088522249d27c03e to your computer and use it in GitHub Desktop.
Quick hack to convert from NetNewsWire 3.x to something you can import into 5.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First, create a new directory, copy this file into it, and run: `npm install xml2js` | |
// Then `plutil -convert xml1 ~/Library/Application\ Support/NetNewsWire/Subscriptions.plist` | |
// Then `node plistToOpml.js > exported.opml` | |
// Then File->Import Subscriptions... in NetNewsWire 5.x | |
const fs = require('fs') | |
const xml2js = require('xml2js') | |
const data = fs.readFileSync(`${process.env.HOME}/Library/Application Support/NetNewsWire/Subscriptions.plist`, 'utf8') | |
const parser = new xml2js.Parser({ explicitChildren: true, preserveChildrenOrder: true }) | |
;(async() => { | |
const result = await parser.parseStringPromise(data) | |
const items = result.plist.array[0].dict.map(item => item.$$) | |
console.log('<opml version="1.0"><body>' + toObjArray(items).map(toXml).join('\n') + '</body><opml>') | |
})() | |
function toObjArray(items) { | |
return items.map(item => { | |
if (item.length % 2 !== 0) throw new Error(JSON.stringify(item)) | |
let itemObj = {} | |
for (let i = 0; i < item.length; i += 2) { | |
if (item[i]['#name'] !== 'key' || !item[i]._) throw new Error(JSON.stringify(item[i])) | |
const key = item[i]._ | |
if (key === 'childrenArray') { | |
itemObj[key] = toObjArray(item[i + 1].dict.map(item => item.$$)) | |
continue | |
} | |
const val = item[i + 1]._ || (['true', 'false'].includes(item[i + 1]['#name']) ? item[i + 1]['#name'] === 'true' : '') | |
itemObj[key] = val | |
} | |
return itemObj | |
}) | |
} | |
function toXml(node) { | |
if (!node.name) return '' | |
const name = node.name.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') | |
return `<outline title="${name}" text="${name}" ${node.rss ? `type="rss" xmlUrl="${node.rss}"` : ''}> | |
${(node.childrenArray || []).map(toXml).join('\n')} | |
</outline>` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instructions (must have
node
installed)Then import that opml file in NetNewsWire 5.x