-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinkedin.js
117 lines (107 loc) · 3.04 KB
/
linkedin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var fs = require('fs');
var https = require('https');
var url = require('url');
var path = require("path");
var osmosis = require('osmosis');
var auth = require('./auth.json');
function saveImage(context, data, selector) {
var src = context.querySelector(selector).getAttribute('src');
var filename = createFileName(data.object.fullName, getFileExt(src));
var filepath = createFilePath('src/img/', filename)
downloadFileFromUrl(src, filepath);
return filename;
}
function saveAsJson(data) {
fs.writeFile('data/linkedin.json', JSON.stringify(data, null, '\t'), function (err) {
if (err) return console.log(err);
});
}
function downloadFileFromUrl(url, dest) {
var file = fs.createWriteStream(dest);
https.get(url, function(response) {
response.pipe(file);
}).on('error', function(err) { // Handle errors
console.log(err)
});
}
function getFileExt(str) {
return path.extname(url.parse(str).pathname);
}
function createFileName(filename, ext) {
return filename.replace(/\s/g,"")+ext;
}
function createFilePath(dir, filename) {
return path.join(dir, filename);
}
osmosis
.get(auth.url)
.follow('.sign-in-link@href')
.login(auth.username, auth.password)
.success('title:contains('+auth.successString+')')
.set('fullName', '#name .full-name')
.set('photo', function(context, data){
return saveImage(context, data, '.profile-picture img');
})
.set({
'publicProfile': '.public-profile a',
'headline': '#headline .title',
'location': '#location .locality a',
'industry': '#location .industry a',
'summary': '#summary-item .description',
'experience': [
osmosis
.find('#background-experience > .section-item')
.set({
'role': 'header > h4',
'company': 'header > h5:last-child',
'location': '.locality',
'startTime': '.experience-date-locale time[1]',
'endTime': '.experience-date-locale time[2]',
'description': '.description'
})
],
'education': [
osmosis
.find('#background-education > .section-item')
.set({
'institute': 'header > h4',
'degree': 'header > h5:last-child',
'startTime': '.education-date time[1]',
'endTime': '.education-date time[2]',
'description': '.notes',
})
.then(function(context, data){
data.startTime = data.startTime.replace(/– /,'');
data.endTime = data.endTime.replace(/– /,'');
})
],
'recommendations': [
osmosis
.find('#endorsements .endorsement-full')
.set({
'fullName': '.endorsement-info > hgroup h5',
'role': '.endorsement-info > hgroup h6',
'date': '.endorsement-date',
'quote': 'blockquote.endorsement-quote p',
})
.set('photo', function(context, data){
return saveImage(context, data, '.endorsement-picture img');
})
],
'awards': [
osmosis
.find('#background-honors .section-item')
.set({
'award': '.honoraward > h4',
'organisation': '.honoraward > h5',
'time': '.honoraward > .honors-date',
})
]
})
.set('interests', '#interests-view')
.data(function(profile) {
saveAsJson(profile);
})
.log(console.log)
.error(console.log)
.debug(console.log);