Forked from ELLIOTTCABLE/gist:84df4798643acafb4bb9
Last active
August 29, 2015 14:01
-
-
Save spion/56f539481d8a8ffa0ac0 to your computer and use it in GitHub Desktop.
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
var raven = require('raven') | |
, Promise = require('bluebird') | |
, requestAsync = require('request-promise') | |
var redis = Promise.promisifyAll(require('redis').createClient()) | |
var languages = JSON.parse(require('fs').readFileSync(__dirname + '/languages.json')).languages | |
Promise.all(languages.map(function(language){ | |
return redis.setAsync('lang:'+language.tag+':name', language.name) | |
.then(_ => Promise.all(language.cats.map(cat => pushSubCategories(cat, language)))) | |
})) | |
.done(function(){ redis.quitAsync() }) | |
function pushSubCategories(category, language, depth){ | |
if (typeof depth != 'number') depth = 0 | |
console.log('woo', depth) | |
return redis.saddAsync('lang:'+language.tag+':cats', category) | |
.then(_ => { | |
console.log(language.tag+' '+depth+':', category) | |
return requestAsync({ | |
url: <...> | |
, json: true | |
, transform: function(resp){ return resp.query.categorymembers } | |
}) | |
.map(member => (depth < 3) ? pushSubCategories(member, language, depth + 1) : null) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment