mirror of
https://github.com/ION606/linkedin-api.git
synced 2026-05-14 22:06:54 +00:00
fixed some issues with searchEmployees
This commit is contained in:
+5
-7
@@ -240,14 +240,14 @@ export default class linkedInAPIClass {
|
|||||||
*/
|
*/
|
||||||
async searchEmployees(keyword, limit = 1000, castToClass = true, filterObfuscated = true, currentCompanies = [], conDeg = []) {
|
async searchEmployees(keyword, limit = 1000, castToClass = true, filterObfuscated = true, currentCompanies = [], conDeg = []) {
|
||||||
const empAll = [],
|
const empAll = [],
|
||||||
lb = (this.logAll) ? new LoadingBar(Math.floor(limit / 10)) : null;
|
lb = (this.logAll) ? new LoadingBar(Math.ceil(limit / 10)) : null;
|
||||||
|
|
||||||
for (let i = 0; empAll.length < limit; i += 50) {
|
for (let i = 0; empAll.length < limit; i += 20) {
|
||||||
let urlExt = `includeWebMetadata=true&variables=(start:${i},origin:FACETED_SEARCH,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(PEOPLE))`;
|
let urlExt = `includeWebMetadata=true&variables=(start:${i},origin:FACETED_SEARCH,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(PEOPLE))`;
|
||||||
|
|
||||||
if (currentCompanies.length) urlExt += `,(key:currentCompany,value:List(${currentCompanies.join(',')}))`;
|
if (currentCompanies.length) urlExt += `,(key:currentCompany,value:List(${currentCompanies.join(',')}))`;
|
||||||
if (conDeg.length) urlExt += `,(key:network,value:List(${numToConDegs(conDeg)}))`;
|
if (conDeg.length) urlExt += `,(key:network,value:List(${numToConDegs(conDeg)}))`;
|
||||||
urlExt += '),includeFiltersInResponse:false),count:50)';
|
urlExt += '),includeFiltersInResponse:false))';
|
||||||
|
|
||||||
const r = await this._makeReq(urlExt);
|
const r = await this._makeReq(urlExt);
|
||||||
|
|
||||||
@@ -263,14 +263,12 @@ export default class linkedInAPIClass {
|
|||||||
else return (e.template === 'UNIVERSAL' && e.title.text !== 'LinkedIn Member');
|
else return (e.template === 'UNIVERSAL' && e.title.text !== 'LinkedIn Member');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.logAll) console.log(r.included?.length, '--->', filtered.length);
|
// if (this.logAll) console.error(r.included?.length, '--->', filtered.length);
|
||||||
|
|
||||||
if (filtered.length) {
|
if (filtered.length) {
|
||||||
if (this.logAll) lb.increment(Math.round(filtered.length / 10));
|
if (this.logAll) lb.increment(Math.ceil(filtered.length / 10));
|
||||||
empAll.push(...filtered);
|
empAll.push(...filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.evade();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!castToClass) return empAll;
|
if (!castToClass) return empAll;
|
||||||
|
|||||||
+5
-6
@@ -14,19 +14,18 @@ export class Company {
|
|||||||
* @note This function skips over any employees who's profile is marked as private
|
* @note This function skips over any employees who's profile is marked as private
|
||||||
*/
|
*/
|
||||||
async getEmployees(limit = Infinity, raw = false) {
|
async getEmployees(limit = Infinity, raw = false) {
|
||||||
const employeesInit = await this.#APIRef._makeReq(`variables=(start:0,origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.urn})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:1)`)
|
const employeesInit = await this.#APIRef._makeReq(`variables=(start:0,origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.entityNum})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:1)`);
|
||||||
|
|
||||||
const numEmp = employeesInit.data.data.searchDashClustersByAll.paging.total,
|
const numEmp = employeesInit.data.data.searchDashClustersByAll.paging.total,
|
||||||
empAll = []
|
empAll = [];
|
||||||
|
|
||||||
|
|
||||||
// since the max cap is 50, we need to iterate until it's over 50
|
// since the max cap is 50, we need to iterate until it's over 50
|
||||||
for (let i = 0; i < numEmp; i += 50) {
|
for (let i = 0; i < numEmp; i += 50) {
|
||||||
if (empAll.length >= limit) break;
|
if (empAll.length >= limit || i >= numEmp) break;
|
||||||
|
|
||||||
const c = (i + 50 >= limit) ? limit - i : 50;
|
const c = (i + 50 >= numEmp) ? numEmp - i : 50;
|
||||||
|
|
||||||
const employeeRes = await this.#APIRef._makeReq(`variables=(start:${i},origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.urn})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:${c})`);
|
const employeeRes = await this.#APIRef._makeReq(`variables=(start:${i},origin:FACETED_SEARCH,query:(flagshipSearchIntent:ORGANIZATIONS_PEOPLE_ALUMNI,queryParameters:List((key:currentCompany,value:List(${this.entityNum})),(key:resultType,value:List(ORGANIZATION_ALUMNI))),includeFiltersInResponse:true),count:${c})`);
|
||||||
const employees = employeeRes.included;
|
const employees = employeeRes.included;
|
||||||
|
|
||||||
const empParsed = employees.filter(e => (e.$type === "com.linkedin.voyager.dash.search.EntityResultViewModel"))
|
const empParsed = employees.filter(e => (e.$type === "com.linkedin.voyager.dash.search.EntityResultViewModel"))
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "linkedin-api-js",
|
"name": "linkedin-api-js",
|
||||||
"version": "1.0.0-13",
|
"version": "1.0.0-14",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
|||||||
+19
-5
@@ -1,15 +1,29 @@
|
|||||||
import LinkedInAPIClass from "../index.js";
|
import LinkedInAPIClass from "../index.js";
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
(async () => {
|
const LAPI = new LinkedInAPIClass(true);
|
||||||
const LAPI = new LinkedInAPIClass(true);
|
|
||||||
|
|
||||||
const o = JSON.parse(fs.readFileSync('config.json'));
|
const o = JSON.parse(fs.readFileSync('config.json'));
|
||||||
await LAPI.login(o.email, o.password);
|
await LAPI.login(o.email, o.password);
|
||||||
|
|
||||||
|
async function smallTest() {
|
||||||
const c = (await LAPI.searchCompanies('microsoft', [5001], 20, 0, true, true)).find(o => (o.name === 'Microsoft'));
|
const c = (await LAPI.searchCompanies('microsoft', [5001], 20, 0, true, true)).find(o => (o.name === 'Microsoft'));
|
||||||
console.log(c);
|
console.log(c);
|
||||||
|
|
||||||
|
const managers = await c.searchEmployees('manager', 20);
|
||||||
|
console.log(managers, managers.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async function largeTest() {
|
||||||
|
const c = (await LAPI.searchCompanies('marukai', null, 1, 0, true, true)).find(o => (o.name === 'Marukai Corporation U.S.A.'));
|
||||||
|
console.log(c);
|
||||||
|
|
||||||
|
console.log(await c.getEmployees());
|
||||||
|
|
||||||
const managers = await c.searchEmployees('manager');
|
const managers = await c.searchEmployees('manager');
|
||||||
console.log(managers, managers.length);
|
console.log(managers, managers.length);
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
|
||||||
|
largeTest();
|
||||||
Reference in New Issue
Block a user