Commit f0a5fa4b by Julian Beisenkötter

better encapsulation

parent 4002386d
var analyse = function (window, url) {
return new Promise(function(resolve, reject){
try {
var links = [];
var profile = {};
var $ = window.$;
profile.url = $("link[rel='canonical']").attr("href");
// Header Info
profile.name = $("h1#name").text();
profile.headline = $("p.headline.title").text();
profile.location = $("dl#demographics .descriptor.adr span.locality").text();
profile.industry = $("dl#demographics dd:nth-child(4)").text();
// Picture
profile.picture = $("profile-picture img").attr('src');
// Featured Info
profile.featured_current = $(".extra-info span.org").text();
profile.featured_past = $(".extra-info span.org").text();
profile.featured_education = $(".extra-info [data-section='educations'] td ol li").text();
profile.contacts = $(".member-connections strong").text();
// Experiences
profile.positions = [];
$("#experience .positions .position").each(function() {
var positionItem = $(this);
var position = {
position: positionItem.find(".item-title").text(),
companyName: positionItem.find(".item-subtitle").text(),
dates: {
from: positionItem.find(".meta .date-range time:nth-child(1)").text(),
to: positionItem.find(".meta .date-range time:nth-child(2)").text()
},
locality: positionItem.find(".meta .location").text(),
description: positionItem.find(".description").text(),
current: (positionItem.attr('data-section') == "currentPositions")
};
profile.positions.push(position);
});
// Skills
profile.skills = [];
$("#skills .pills li").each(function(){
var skill = $(this);
var more = skill.hasClass('see-more');
var less = skill.hasClass('see-less');
if(!more && !less){
profile.skills.push(skill.text());
}
});
// Education
profile.educations = [];
$("#education .schools .school").each(function() {
var schoolItem = $(this);
var school = {
school: schoolItem.find(".item-title").text(),
course: schoolItem.find(".item-subtitle").text(),
dates: {
from: schoolItem.find(".meta .date-range time:nth-child(1)").text(),
to: schoolItem.find(".meta .date-range time:nth-child(2)").text()
},
description: schoolItem.find(".description p").text()
};
profile.educations.push(school);
});
$('.browse-map .profile-card a').each(function(){
var link = $(this).attr('href');
links.push(link);
});
resolve({profile: profile, links: links})
} catch (err) {
reject(err)
}
});
};
module.exports = analyse;
// Scrape a linkedin profile for the public contents
var Promise = require("bluebird");
var analyser = require("./analyser");
var retrieve = require("./retrieve");
function getProfile(param, withlinks) {
return new Promise(function(resolve, reject){
retrieve(param) // retrieve Profile
.then(function(window){
return analyser(window); // Analyse Page
})
.then(function(result){
if(withlinks){
resolve(result); // resolve to obj: {profile, links}
}else{
resolve(result.profile);// resolve to profile
}
}).catch(function(err){
reject(err);
});
});
}
module.exports = getProfile;
module.exports = require('./src/index');
......@@ -19,5 +19,8 @@
"bluebird": "^3.3.1",
"jquery": "^2.1.3",
"jsdom": "5.6.1"
},
"devDependencies": {
"request-promise": "^2.0.1"
}
}
var baseAnalysis = function($, profile){
profile.url = $("link[rel='canonical']").attr("href");
profile.contacts = $(".member-connections strong").text();
// Header Info
profile.name = $("h1#name").text();
profile.headline = $("p.headline.title").text();
profile.location = $("dl#demographics .descriptor.adr span.locality").text();
profile.industry = $("dl#demographics dd:nth-child(4)").text();
// Picture
profile.picture = $("profile-picture img").attr('src');
return profile;
}
module.exports = baseAnalysis;
var educationsAnalysis = function($, profile){
// Education
profile.educations = [];
$("#education .schools .school").each(function() {
var schoolItem = $(this);
var school = {
school: schoolItem.find(".item-title").text(),
course: schoolItem.find(".item-subtitle").text(),
dates: {
from: schoolItem.find(".meta .date-range time:nth-child(1)").text(),
to: schoolItem.find(".meta .date-range time:nth-child(2)").text()
},
description: schoolItem.find(".description p").text()
};
profile.educations.push(school);
});
return profile;
};
module.exports = educationsAnalysis;
var featuredAnalysis = function($, profile){
// Featured Info
profile.featured_current = $(".extra-info span.org").text();
profile.featured_past = $(".extra-info span.org").text();
profile.featured_education = $(".extra-info [data-section='educations'] td ol li").text();
return profile;
}
module.exports = featuredAnalysis;
var linkedPeople = function($, links){
var links = [];
$('.browse-map .profile-card a').each(function(){
var link = $(this).attr('href');
links.push(link);
});
return links;
};
module.exports = linkedPeople;
var positionsAnalysis = function($, profile){
// Experiences
profile.positions = [];
$("#experience .positions .position").each(function() {
var positionItem = $(this);
var position = {
position: positionItem.find(".item-title").text(),
companyName: positionItem.find(".item-subtitle").text(),
dates: {
from: positionItem.find(".meta .date-range time:nth-child(1)").text(),
to: positionItem.find(".meta .date-range time:nth-child(2)").text()
},
locality: positionItem.find(".meta .location").text(),
description: positionItem.find(".description").text(),
current: (positionItem.attr('data-section') == "currentPositions")
};
profile.positions.push(position);
});
return profile;
};
module.exports = positionsAnalysis;
var skillsAnalysis = function($, profile){
// Skills
profile.skills = [];
$("#skills .pills li").each(function(){
var skill = $(this);
var more = skill.hasClass('see-more');
var less = skill.hasClass('see-less');
if(!more && !less){
profile.skills.push(skill.text());
}
});
return profile;
}
module.exports = skillsAnalysis;
var Profile = require('./profile');
var linkedPeople = require('./analyse-parts/linkedPeople');
var analyse = function (window, url) {
return new Promise(function(resolve, reject){
try {
var $ = window.$;
var profile = new Profile($)
.base()
.featured()
.positions()
.skills()
.educations()
.clean();
links = linkedPeople($);
resolve({profile: profile, links: links})
} catch (err) {
reject(err)
}
});
};
module.exports = analyse;
// Scrape a linkedin profile for the public contents
var Promise = require("bluebird");
var analyser = require("./analyser");
var retrieve = require("./retrieve");
function getProfile(param, withlinks) {
return new Promise(function(resolve, reject){
retrieve(param) // retrieve Profile
.then(function(window){
return analyser(window); // Analyse Page
})
.then(function(result){
if(withlinks){
resolve(result); // resolve to obj: {profile, links}
}else{
resolve(result.profile);// resolve to profile
}
}).catch(function(err){
reject(err);
});
});
}
module.exports = getProfile;
"use strict";
var baseAnalysis = require('./analyse-parts/base');
var featuredAnalysis = require('./analyse-parts/featured');
var positionsAnalysis = require('./analyse-parts/positions');
var skillsAnalysis = require('./analyse-parts/skills');
var educationsAnalysis = require('./analyse-parts/educations');
class Profile {
constructor($) {
this.$ = $;
}
base(){
return baseAnalysis(this.$, this);
}
featured(){
return featuredAnalysis(this.$, this)
}
positions(){
return positionsAnalysis(this.$, this)
}
skills(){
return skillsAnalysis(this.$, this)
}
educations(){
return educationsAnalysis(this.$, this)
}
clean(){
delete this.$
return this;
}
};
module.exports = Profile;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment