Files
weval-l99/v98-linkedin-session-inject.py
2026-04-20 15:39:16 +02:00

50 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
# V98 Inject LI_AT cookie from secrets.env into Chromium persistent session
# One-time call after Yacine provides cookie
import asyncio, os, subprocess
from pathlib import Path
SESSION_DIR = Path('/opt/weval-l99/browser-sessions/linkedin')
SESSION_DIR.mkdir(parents=True, exist_ok=True)
def get_cookie():
try:
r = subprocess.run(['grep', '^LI_AT=', '/etc/weval/secrets.env'], capture_output=True, text=True, timeout=3)
if r.returncode == 0:
return r.stdout.strip().split('=', 1)[1]
except: pass
return None
async def main():
from playwright.async_api import async_playwright
cookie = get_cookie()
if not cookie:
print('{"ok":false,"err":"no LI_AT in /etc/weval/secrets.env","instruction":"Yacine: add LI_AT=<your_linkedin_session_cookie> to /etc/weval/secrets.env (F12 > Application > Cookies > .linkedin.com > li_at)"}')
return
async with async_playwright() as p:
ctx = await p.chromium.launch_persistent_context(
str(SESSION_DIR),
headless=True,
user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
)
await ctx.add_cookies([{
'name': 'li_at',
'value': cookie,
'domain': '.linkedin.com',
'path': '/',
'httpOnly': True,
'secure': True,
'sameSite': 'None',
}])
page = await ctx.new_page()
await page.goto('https://www.linkedin.com/feed/', wait_until='domcontentloaded', timeout=20000)
await page.wait_for_timeout(3000)
url = page.url
logged = 'login' not in url and 'checkpoint' not in url
print('{"ok":true,"logged_in":' + ('true' if logged else 'false') + ',"url":"' + url[:200] + '"}')
await ctx.close()
asyncio.run(main())