File size: 1,662 Bytes
0ee2df7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
LinkedIn via the unofficial linkedin-api package, authenticated with an
li_at session cookie from a dedicated research account. Keep volume low
(<100 lookups/day) and refresh the cookie monthly.
"""
from linkedin_api import Linkedin
from supabase_client import require_tool_keys


def _get_client() -> Linkedin:
    creds = require_tool_keys("linkedin")
    li_at = creds["api_key"]
    return Linkedin("", "", cookies={"li_at": li_at})


def run(params: dict) -> dict:
    mode = params.get("mode")
    target = params.get("target")
    if mode not in ("profile", "people_search", "company") or not target:
        raise ValueError("mode must be 'profile' | 'people_search' | 'company', target is required")
    limit = int(params.get("limit", 25))

    api = _get_client()

    if mode == "profile":
        profile = api.get_profile(target)
        return {
            "name": f"{profile.get('firstName', '')} {profile.get('lastName', '')}".strip(),
            "headline": profile.get("headline"),
            "location": profile.get("locationName"),
            "current_company": (profile.get("experience") or [{}])[0].get("companyName"),
        }

    if mode == "people_search":
        people = api.search_people(keywords=target, network_depths=["F", "S"])
        return {"count": len(people[:limit]), "results": people[:limit]}

    company = api.get_company(target)
    return {
        "name": company.get("name"),
        "employee_count": company.get("staffCount"),
        "industry": (company.get("companyIndustries") or [{}])[0].get("localizedName"),
        "follower_count": company.get("followingInfo", {}).get("followerCount"),
    }