← back to Rentv Sheet Enrich Refine
local_li.py
42 lines
#!/usr/bin/env python3
"""
local_li.py <batchfile.json> — $0 LOCAL company-LinkedIn via openclaw real browser.
For each company in the batch, drives the proven openclaw LinkedIn finder
(la-socrata-ingester/scripts/linkedin-openclaw.js --name=...), parses the real
linkedin.com/company/... href it returns, and writes it to the master's
LinkedIn (Company) column via write_by_name.py. TRUTHFUL by construction — we only
accept a URL openclaw actually rendered from a live Google result (no LLM guessing).
"""
import sys, os, json, re, subprocess
OC = os.path.expanduser("~/Projects/la-socrata-ingester/scripts/linkedin-openclaw.js")
def company_li(name):
try:
out = subprocess.run(["node", OC, f"--name={name}"], cwd=os.path.dirname(OC),
capture_output=True, text=True, timeout=75).stdout
except Exception:
return ""
# tool prints "→ <Company>: https://www.linkedin.com/company/<slug>"
m = re.search(r'https?://(?:www\.)?linkedin\.com/company/[A-Za-z0-9\-_%]+', out)
return m.group(0) if m else ""
def main():
batch = json.load(open(sys.argv[1]))
gid = batch["gid"]; targets = batch["targets"]
res = []
for t in targets:
comp = t["company"]
li = company_li(comp)
print(f" {comp[:34]:34s} -> {li or '(none)'}", flush=True)
if li:
res.append({"company": comp, "company_li": li})
out = sys.argv[1].replace(".json", "_li.json")
json.dump(res, open(out, "w"))
print(f"{len(res)}/{len(targets)} company LinkedIn found -> {out}", flush=True)
if res:
subprocess.run(["python3", os.path.join(os.path.dirname(__file__),"write_by_name.py"), str(gid), out])
if __name__ == "__main__":
main()