From ee230e3a1a9e1510a8305a3ff35a0baa5ee1fa8b Mon Sep 17 00:00:00 2001 From: Josiah Bradbury Date: Sun, 12 May 2019 08:00:22 -0500 Subject: [PATCH] Repos to pull from list like Blogs (#11) * Reimplimented Repos pulling from list. * added repos.json back in --- assets/index.html | 19 ++++++++++++++++++ build.js | 50 ++++++++++++++++++++++++++++------------------- repos.js | 45 ++++++++++++++++++++++++++++++++++++++++++ repos/repos.json | 0 4 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 repos.js create mode 100644 repos/repos.json diff --git a/assets/index.html b/assets/index.html index 929185e..6ddad48 100644 --- a/assets/index.html +++ b/assets/index.html @@ -62,6 +62,25 @@ `) } }); + $.getJSON("./repos/repos.json", function(repos){ + for(var i = 0; i < repos.length; i++){ + $("#projects").append(` + +
+
${repos[i].name}
+
+ ${repos[i].description} +
+
+   ${repos[i].language} +   ${repos[i].stargazers_count} +   ${repos[i].forks_count} +
+
+
+ `) + } + }); \ No newline at end of file diff --git a/build.js b/build.js index ad4b281..c87b89f 100644 --- a/build.js +++ b/build.js @@ -76,26 +76,6 @@ jsdom.fromFile("./assets/index.html", options).then(function (dom) { (async () => { try { console.log("Building HTML/CSS..."); - var repos = await got(`https://api.github.com/users/${username}/repos?sort=created`); - repos = JSON.parse(repos.body); - for(var i = 0;i < repos.length;i++){ - if(repos[i].fork == false){ - document.getElementById("projects").innerHTML += ` - -
-
${repos[i].name}
-
- ${convertToEmoji(repos[i].description)} -
-
-   ${repos[i].language} -   ${repos[i].stargazers_count} -   ${repos[i].forks_count} -
-
-
`; - } - } var user = await got(`https://api.github.com/users/${username}`); user = JSON.parse(user.body); document.title = user.login; @@ -155,8 +135,38 @@ jsdom.fromFile("./blog/blog_template.html", options).then(function (dom) { }); } +function PopulateRepos(username){ + var repoData = []; + (async () => { + try { + var repos = await got(`https://api.github.com/users/${username}/repos?sort=created`); + repos = JSON.parse(repos.body); + for(var i = 0;i < repos.length;i++){ + if(repos[i].fork == false){ + repoData.push({ + "html_url": repos[i].html_url, + "name": repos[i].name, + "description": repos[i].description, + "language": repos[i].language, + "stargazers_count": repos[i].stargazers_count, + "forks_count" :repos[i].forks_count + }); + } + + } + fs.writeFile('./repos/repos.json', JSON.stringify(repoData), function(err){ + if (err) throw err; + console.log('Repos Created Successfully in repos folder.'); + }); + } catch (error) { + console.log(error); + } +})(); +} + if (program.name) { populateHTML(('%s', program.name)); + PopulateRepos(('%s', program.name)); } else { console.log("Provide a username"); } \ No newline at end of file diff --git a/repos.js b/repos.js new file mode 100644 index 0000000..58faa31 --- /dev/null +++ b/repos.js @@ -0,0 +1,45 @@ +const program = require('commander'); +const fs = require('fs'); +const got = require('got'); +options = { + resources: "usable" +}; + +program + .version('0.1.0') + .option('-n, --name [username]', 'get username') + .parse(process.argv); + +function PopulateRepos(username){ + var repoData = []; + (async () => { + try { + var repos = await got(`https://api.github.com/users/${username}/repos?sort=created`); + repos = JSON.parse(repos.body); + for(var i = 0;i < repos.length;i++){ + if(repos[i].fork == false){ + repoData.push({ + "html_url": repos[i].html_url, + "name": repos[i].name, + "description": repos[i].description, + "language": repos[i].language, + "stargazers_count": repos[i].stargazers_count, + "forks_count" :repos[i].forks_count + }); + } + + } + fs.writeFile('./repos/repos.json', JSON.stringify(repoData), function(err){ + if (err) throw err; + console.log('Repos Created Successfully in repos folder.'); + }); + } catch (error) { + console.log(error); + } +})(); +} +if (program.name) { + PopulateRepos(('%s', program.name)); +} else { + console.log("provide a name to scrape repos"); +} \ No newline at end of file diff --git a/repos/repos.json b/repos/repos.json new file mode 100644 index 0000000..e69de29