Created
June 16, 2017 19:38
-
-
Save cacheflow/acc04d2736855134555664415fb5c177 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
const scrapePackages = () => { | |
fs.readFile('./temp/username.txt', 'utf-8', (err, data) => { | |
if (err) throw err; | |
let username = data | |
let $; | |
let npmModuleUrl; | |
let $$; | |
let obj = {} | |
let packageName; | |
request(`https://www.npmjs.com/~${username}`, (err, res) => { | |
$ = cheerio.load(res.body) | |
let packageLinks = $('.collaborated-packages').children('li').children('a') | |
packageLinks.each(function(i, elem) { | |
// console.log($(elem).attr('href')) | |
npmModuleUrl = $(elem).attr('href') | |
request(`https://www.npmjs.com${npmModuleUrl}`, (err, res) => { | |
$$ = cheerio.load(res.body) | |
// console.log(res.body) | |
packageName = $(elem).attr('href').split('/package')[1].split('/')[1] | |
obj = Object.assign(obj, {[packageName]: { | |
daily: $$('.daily-downloads').text(), | |
weekly: $$('.weekly-downloads').text(), | |
monthly: $$('.monthly-downloads').text() | |
}}) | |
console.log(Object.keys(obj).length) | |
if(Object.keys(obj).length == packageLinks.length ) { | |
askUserWhichPackagesToDisplay(obj) | |
} | |
}) | |
}) | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment