added the 'limits' param for company search

This commit is contained in:
2024-05-11 06:01:39 -07:00
parent 5ff71b90e8
commit 09e2d79c28
3 changed files with 21 additions and 13 deletions
+14 -5
View File
@@ -190,28 +190,37 @@ export default class linkedInAPIClass {
/**
* @param {String} keyword i.e. "biotechnology"
* @param {Array<Number>?} numEmp
* @param {Number?} [limit=1000] the function will use the bound the given number is contained in (see {@link findRangeIndex} for ranges)
* @param {Number?} [start=0]
* @param {boolean?} [castToClass=true] whether the function should return a list of Company classes or just raw JSON
* @param {boolean} [excludeGeneric=false]
* @returns {Promise<[SocialActivityCounts | Group | Company | GenericEntity]>}
*/
async searchCompanies(keyword, numEmp = undefined, start = 0, castToClass = true, excludeGeneric = false) {
let urlExt = `variables=(start:${start},origin:GLOBAL_SEARCH_HEADER,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(COMPANIES))${(numEmp) ? `,(key:companySize,value:List(${numsToSizes(...numEmp)}))` : ''}),includeFiltersInResponse:false))`;
async searchCompanies(keyword, numEmp = undefined, limit = 1000, start = 0, castToClass = true, excludeGeneric = false) {
const compAll = [];
for (let i = start; i < limit; i += 50) {
let urlExt = `variables=(start:${i},origin:GLOBAL_SEARCH_HEADER,query:(keywords:${keyword},flagshipSearchIntent:SEARCH_SRP,queryParameters:List((key:resultType,value:List(COMPANIES))${(numEmp) ? `,(key:companySize,value:List(${numsToSizes(...numEmp)}))` : ''}),includeFiltersInResponse:false))`;
const r = await this._makeReq(urlExt);
if (!r?.included && r?.data?.errors) {
console.error(JSON.stringify(r.data.errors))
throw "ERROR!";
}
if (!castToClass) return r;
else return parseResponse(r, this, excludeGeneric);
if (!castToClass) compAll.push(r);
else compAll.push(await parseResponse(r, this, excludeGeneric));
await this.evade();
}
return compAll.flat();
}
/**
* @returns {Promise<LinkedInProfile[]>}
* @param {String} keyword the user to search for
* @param {Number?} [limit=1000] the function will find the bound the given number is contained in (see {@link findRangeIndex} for ranges)
* @param {Number?} [limit=1000] the function will use the bound the given number is contained in (see {@link findRangeIndex} for ranges)
* @param {boolean?} [castToClass=true] whether the function should return a list of Company classes or just raw JSON
* @param {boolean} [filterObfuscated=true] where or not to filter out members with obfuscated profiles ("LinkedIn Member")
* @param {Array<String>?} currentCompanies
+1 -1
View File
@@ -7,7 +7,7 @@
},
"type": "module",
"name": "linkedin-api-js",
"version": "1.0.0-7",
"version": "1.0.0-9",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
+1 -2
View File
@@ -7,8 +7,7 @@ import fs from 'fs';
const o = JSON.parse(fs.readFileSync('config.json'));
await LAPI.login(o.email, o.password);
const c = await LAPI.searchCompanies('microsoft', [10, 500, 5000], 0, true, true);
const c = await LAPI.searchCompanies('microsoft', [10, 500, 5000], 20, 0, true, true);
console.log(c);
const managers = await c.find(o => (o.name === 'Microsoft')).searchEmployees('manager', 5);