Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added images/1592192122667-Razielini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1592192163523-Razielini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1592192204595-Razielini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/1592233078422-Razielini.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/githubUser.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,135 changes: 2,135 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"author": "Oscar Barajas <oscar@platzi.com>",
"license": "MIT",
"dependencies": {
"dotenv": "^8.2.0",
"node-fetch": "^2.6.0",
"prompt": "^1.0.0",
"puppeteer": "^2.1.1"
Expand Down
28 changes: 18 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
const prompt = require('prompt')
const prompt = require('prompt');
const { getDataFromGithub } = require('./utils/getDataFromGithub');

const count = 1

const prompt_attributes = [{
const promptAttributes = [{
name: 'githubUser',
}]
type: 'string',
message: 'Is your username on github.',
default: 'Razielini',
required: true,
}];

prompt.get(prompt_attributes, (err, result) => {
prompt.get(promptAttributes, (err, result) => {
if (err) {
console.log(err);
return 1;
}
console.log('Command-line received data:');
})

prompt.start()
const user = result.githubUser;

if (!user) return false;

getDataFromGithub(user);

});

prompt.start();
15 changes: 12 additions & 3 deletions src/utils/getDataFromGithub.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
const puppeteer = require('puppeteer');
const { getTime } = require('./getTime');
const { postToSlack } = require('./postToSlack');

const getDataFromGithub = async (githubUser) => {
console.log('Launch Puppeteer');
const browser = await puppeteer.launch();
const page = await browser.newPage();

const githubUrl = 'https://github.com/';
await page.goto(`${githubUrl}${githubUser}`);
await page.screenshot({ path: `src/images/${getTime()}-${githubUser}.png` });
await page.screenshot({ path: `images/${getTime()}-${githubUser}.png` });

const githubCounter = await page.evaluate(() => document.getElementsByClassName('Counter')[0].innerText);
const githubUserPhoto await page.evaluate(() => document.getElementsByClassName('avatar-before-user-status')[0].src);
const githubUserPhoto = await page.evaluate(() => document.getElementsByClassName('avatar-before-user-status')[0].src);

postToSlack(githubUser, githubUserPhoto, githubCounter);
await browser.close();
};

module.exports = {
getDataFromGithub,
};
6 changes: 6 additions & 0 deletions src/utils/getTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const getTime = () => Date.now();

module.exports = {
getTime,
};
10 changes: 9 additions & 1 deletion src/utils/postToSlack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
const fetch = require('node-fetch');
const dotenv = require('dotenv');

dotenv.config();

const postToSlack = async (user, photo, count) => {
const webhookURL = `${process.env.HOOK}${process.env.TOKEN}`;
const data = JSON.stringify({
'blocks': [
{
Expand All @@ -24,6 +28,10 @@ const postToSlack = async (user, photo, count) => {
},
body: data,
}).then((response) => {
console.log(response.size);
// console.log(response.size);
});
};

module.exports = {
postToSlack,
};