Created
October 1, 2015 21:08
-
-
Save jonasfj/e094784fb15127538ec3 to your computer and use it in GitHub Desktop.
Quick hack to export all my etherpads as text...
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
// npm install babel promise superagent superagent-promise | |
// ./node_modules/.bin/babel-node export.js | |
var pads = [ | |
'jonasfj-pad-list' | |
]; | |
var seen = ['jonasfj-pad-list']; | |
var fs = require('fs'); | |
var Promise = require('promise'); | |
var request = require('superagent-promise')(require('superagent'), Promise); | |
// Return all pattern matches with captured groups | |
var execAll = function(string) { | |
var r = /https:\/\/etherpad.mozilla.org\/([A-Za-z-0-9_-]+)/g; | |
var match = null; | |
var matches = new Array(); | |
while (match = r.exec(string)) { | |
var matchArray = []; | |
for (var i in match) { | |
if (parseInt(i) == i) { | |
matchArray.push(match[i]); | |
} | |
} | |
matches.push(matchArray); | |
} | |
return matches; | |
}; | |
(async() => { | |
while(pads.length > 0) { | |
var pad = pads.pop(); | |
var url = 'https://etherpad.mozilla.org/ep/pad/export/' + pad + '/latest?format=txt'; | |
try { | |
var res = await request.get(url).end(); | |
fs.writeFileSync('data/' + pad + '.txt', res.text); | |
execAll(res.text).forEach(l => { | |
if (!seen.includes(l[1])) { | |
pads.push(l[1]); | |
seen.push(l[1]); | |
} | |
}); | |
console.log(" - " + pad); | |
} catch(e) { | |
console.log("Failed to get:" + pad); | |
} | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment