Created
October 1, 2015 21:14
-
-
Save jonasfj/b18dc1c78e48efa35c7d to your computer and use it in GitHub Desktop.
Export linked etherpads as html... just a quick hacl...
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=html'; | |
try { | |
var res = await request.get(url).end(); | |
var t = res.text.replace(/https:\/\/etherpad.mozilla.org\/([A-Za-z-0-9_-]+)/g, function(a, l) { | |
return l + '.htm'; | |
}); | |
fs.writeFileSync('data/' + pad + '.htm', t); | |
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