Skip to content

Commit

Permalink
fix profile parser. (workaround sloppy DOM) #91
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Apr 10, 2019
1 parent 6b59190 commit 38bf694
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
25 changes: 13 additions & 12 deletions lib/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module.exports = function profile($, url, callback) {
var data = { url: url };
// console.log("$('.avatar')", $('.avatar'));
data.img = $('.avatar-before-user-status').attr('src');
data.img = $('.u-photo').attr('href');
// console.log('data:', data);

var parts = data.img.split('/');
Expand All @@ -33,16 +33,16 @@ module.exports = function profile($, url, callback) {
data.following = stats[4]; // number of people this user is following

// Pinned Repos
data.pinned = [];
var p = '.pinned-repo-item-content:nth-of-type('
var urls = $('.pinned-repo-item-content a.text-bold')
for (var i = 0; i < $('.pinned-repo-item-content').length; i++) {
var pin = {
url: urls[i].attribs.href,
[];
var repos = $('.pinned-item-list-item')

// console.log('repos: ', repos);
data.pinned = repos.map(function (i) {
return {
url: $(this).find('a.text-bold')[0]['attribs']['href'],
// Want More? see: https://github.com/nelsonic/github-scraper/issues/78
}
data.pinned.push(pin);
}
});

// // General Info
data.worksfor = $('.p-org').first().text().trim(); // Works for
Expand All @@ -56,7 +56,6 @@ module.exports = function profile($, url, callback) {
// Contributions to Open Source in the past 12 months
data.contribs = parseInt($('.js-yearly-contributions').text().trim()
.split(' contributions')[0].replace(',', ''), 10);
console.log('data.contribs:', data.contribs);
// Contribution Matrix
data = require('./profile_contribs.js')($, data);

Expand All @@ -71,8 +70,10 @@ module.exports = function profile($, url, callback) {
})

// GitHub Developer Program member?
var member = $('.member-badge');
if(member && member[0] && member[0].attribs.href === 'https://developer.github.com') {
var member = $('.bg-purple').text().trim();
// yes this is always on the page but the hide it using CSS!! :-(
var display = $('.bg-purple').parent().hasClass('d-none');
if(member && member === 'Pro' && !display) {
data.developerprogram = true;
}
callback(null, data);
Expand Down
14 changes: 7 additions & 7 deletions test/profile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ test(file + 'Scrape @nelsonic GitHub profile (consistent state profile)', functi
var user = 'nelsonic';
profile(user, function (err, data) {
// console.log('data.img:', data.img)

t.ok(data.img.match(/githubusercontent.com\/u\/194400/) !== null,
'Image is what we expect: ' + data.img);
t.ok(data.uid === 194400, '@' + user + ' has GitHub user_id: ' + data.uid);
Expand All @@ -29,27 +28,28 @@ test(file + 'Scrape @nelsonic GitHub profile (consistent state profile)', functi
+ ' contributions to Open Source this year!');

t.ok(data.pinned.length === 6, '- @' + user + ' Has Six "Pinned" Repositories');
/*
t.ok(Object.keys(data.orgs).length > 6, '- @' + user + ' Is a member of '

t.ok(Object.keys(data.orgs).length > 2, '- @' + user + ' Is a member of '
+ Object.keys(data.orgs).length + ' Orgs');

t.ok(data.developerprogram === true, '- @'
+ user + ' is a member of the "GitHub Developer Program"');
// regression: https://github.com/nelsonic/github-scraper/issues/79
t.ok(data.stars > 2000, '- @' + user + ' Has starred ' + data.stars);
*/

t.end();
});
});

test.skip(file + 'Check @olizilla profile IS NOT GitHub Developer Program Member', function(t){
var url = 'olizilla';
test(file + 'Check @torvalds profile IS NOT GitHub Developer Program Member', function(t){
var url = 'torvalds';
profile(url, function(err, data) {
t.ok(typeof data.developerprogram === 'undefined', '- @' + url + ' is NOT a member of the "GitHub Developer Program"');
t.end();
});
});

test.skip(file + 'Scrape @iteles detailed contribution matrix', function(t){
test(file + 'Scrape @iteles detailed contribution matrix', function(t){
var user = 'iteles';
profile(user, function(err, data) {
// console.log(data)
Expand Down

0 comments on commit 38bf694

Please sign in to comment.