Skip to content

Instantly share code, notes, and snippets.

@icebob
Created August 22, 2020 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icebob/022ab2176075e22c4f076fb1130cb5fe to your computer and use it in GitHub Desktop.
Save icebob/022ab2176075e22c4f076fb1130cb5fe to your computer and use it in GitHub Desktop.
Convert Github stars to csv
const fetch = require("node-fetch");
const { createWriteStream, existsSync } = require("fs");
const fs = require("fs").promises;
const outputFileName = "stars.csv";
const githubUser = "icebob";
function log(msg) {
console.log(`[${new Date().toISOString().substr(11, 8)}] -`, msg);
}
async function start() {
const f = createWriteStream(outputFileName);
f.write("Repo,URL,Description,Stars,Language,Last Update\n")
let page = 1;
while (true) {
const pageFilename = `page-${page}.json`;
let json;
if (existsSync(pageFilename)) {
log(`Load page ${page} from file...`);
const content = await fs.readFile(pageFilename, "utf8");
json = JSON.parse(content);
} else {
log(`Download page ${page}...`);
const res = await fetch(`https://api.github.com/users/${githubUser}/starred?page=${page}&per_page=100`);
const content = await res.text();
await fs.writeFile(`page-${page}.json`, content, "utf8");
json = JSON.parse(content);
}
if (json.length == 0) break;
log("Processing data...");
for(star of json) {
const row = [];
row.push(star.full_name, star.html_url, '"' + star.description + '"', star.stargazers_count, star.language, star.updated_at)
f.write(row.join(",") + "\n");
}
page++;
}
f.close();
log("Done.");
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment