Last active
August 29, 2015 14:19
-
-
Save imwm/5c78ee555f8b4e45243b to your computer and use it in GitHub Desktop.
This file contains 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
//requires up here | |
var kimonoApiKey = "***********"; | |
var siteIds = [ | |
"496ix4qu", //Daily Intelligencer | |
"451rb3y0", //Mashable --> To Delete (improperly formatted) | |
"9p482mnm", //Vox Dot Com | |
"464bh2bk", //i09 | |
"b9kri09g", //Mediaite | |
"3airwaci", //Gizmodo | |
"bo1cnun6", //Gawker | |
"a3t5oodc" //Jezebel | |
]; | |
var stashArray = []; | |
//Make a request for all sites | |
hts.iterateThroughSites = function(arrayOfSites, outputArray, renderCallback) { | |
async.each(arrayOfSites, function(siteId, callback) { | |
//console.log(siteId); | |
request(hts.getRequestUrlFor(siteId), function(err, response, body) { | |
console.log("making request"); | |
var parsedBody = JSON.parse(body); | |
//console.log(parsedBody); | |
hatTipList = parsedBody.results.collection1; | |
var urlCache = []; | |
//console.log(hatTipList); | |
for (i in hatTipList) { | |
var thisItem = hatTipList[i]; | |
if (typeof thisItem.property1.href == "string") { | |
var sourceUrl = parseUrl(thisItem.property1.href).hostname; | |
//console.log(sourceUrl); | |
urlCache.push(sourceUrl); | |
} else if (typeof thisItem.property1 == "string") { | |
var sourceUrl = parseUrl(thisItem.property1).hostname; | |
//console.log(sourceUrl); | |
urlCache.push(sourceUrl); | |
} | |
}; | |
//console.log(urlCache); | |
outputArray.push(urlCache); | |
//console.log(outputArray); | |
}); | |
callback(null, outputArray); | |
}, function(err, result){ | |
if (err) { | |
console.log("error"); | |
} | |
else { | |
renderCallback(null, outputArray); | |
} | |
}); | |
}; | |
async.waterfall([ | |
function(renderCallback) { | |
//console.log("first item in waterfall"); | |
hts.iterateThroughSites(siteIds, stashArray, renderCallback); | |
}, | |
function(outputArray, callback) { | |
console.log("second item in waterfall"); | |
router.get('/', function(req, res, next) { | |
res.render('index', { | |
title: 'Sources!', | |
sourceList: outputArray | |
}); | |
}); | |
callback(null); | |
} | |
], null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment