Last active
March 6, 2020 15:07
-
-
Save yangfch3/5b3ee7efd535ab63cd56 to your computer and use it in GitHub Desktop.
拉取你的 github star 列表
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
const fs = require('fs'), | |
child_exe = require('child_process'); | |
let page = 1, | |
perPage = 20; | |
function autoCrawl() { | |
child_exe.exec(`curl https://api.github.com/users/yangfch3/starred?page=${page} --silent`, function (err, stdout, stderr) { | |
let data = stdout, | |
dataArr = JSON.parse(data), | |
output = ''; | |
if (dataArr.length === 0) { | |
return; | |
} | |
console.log('本页第一个 item: ' + dataArr[0].full_name); | |
for (let meta of dataArr) { | |
output += '[' + meta.full_name + ']' + '(' + meta.html_url + ')' + '\n' + ': ' + meta.description + '\n\n'; | |
} | |
fs.appendFileSync('output.md', output); | |
if (dataArr.length < perPage) { | |
console.log(`全部拉取完毕!`); | |
return; | |
} else { | |
console.log(`第 ${page} 页拉取成功;`); | |
page++; | |
autoCrawl(); | |
} | |
}) | |
} | |
autoCrawl(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment