Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(linkedin): correct field mapping + surface articles as high signal

Matt Van Horn732d4ae76b52
diff --git a/CONFIGURATION.md b/CONFIGURATION.md
index d527b16a..12360d24 100644
--- a/CONFIGURATION.md
+++ b/CONFIGURATION.md
@@ -99,7 +99,7 @@ The project-scoped file is useful for **intentional per-client setups**: drop a
| Instagram | `SCRAPECREATORS_API_KEY` + `INCLUDE_SOURCES` contains `instagram` | Instagram Reels | 10K free calls; raise `LAST30DAYS_TRANSCRIPT_TIMEOUT` (default 30s) if SC is slow on your network |
| Threads | `SCRAPECREATORS_API_KEY` + `INCLUDE_SOURCES` contains `threads` | Threads items | 10K free calls |
| Pinterest | `SCRAPECREATORS_API_KEY` + `INCLUDE_SOURCES` contains `pinterest` | Pinterest items | 10K free calls |
-| LinkedIn | `SCRAPECREATORS_API_KEY` + `INCLUDE_SOURCES` contains `linkedin` | LinkedIn posts | 10K free calls; power-user opt-in, not offered during first-run onboarding |
+| LinkedIn | `SCRAPECREATORS_API_KEY` + `INCLUDE_SOURCES` contains `linkedin` | LinkedIn posts + articles (articles rank as high signal on person topics) | 10K free calls; power-user opt-in, not offered during first-run onboarding |
| Bluesky | `BSKY_HANDLE` + `BSKY_APP_PASSWORD` | Bluesky items | yes (app password at bsky.app) |
| TruthSocial | `TRUTHSOCIAL_TOKEN` | TruthSocial items | yes |
| Web search | one of: `BRAVE_API_KEY`, `EXA_API_KEY`, `SERPER_API_KEY`, `PARALLEL_API_KEY` | `--auto-resolve` and Step 2 supplements | Brave has a free tier; native WebSearch on Claude Code / Codex / Gemini works as a fallback |
diff --git a/skills/last30days/scripts/lib/linkedin.py b/skills/last30days/scripts/lib/linkedin.py
index ceb88dce..07b28142 100644
--- a/skills/last30days/scripts/lib/linkedin.py
+++ b/skills/last30days/scripts/lib/linkedin.py
@@ -114,6 +114,21 @@ def _int_field(post: dict[str, Any], *keys: str) -> int:
return 0
+def _is_article(url: str) -> bool:
+ """A LinkedIn long-form article (Pulse) lives under a /pulse/ URL.
+
+ Articles are higher-signal than ordinary posts — someone who wrote a
+ full article on a topic is a stronger source than someone who dashed off
+ a status update.
+ """
+ return "/pulse/" in (url or "").lower()
+
+
+# Relevance hints: articles outrank ordinary posts at rerank time.
+_ARTICLE_RELEVANCE = 0.9
+_POST_RELEVANCE = 0.5
+
+
def parse_linkedin_response(
result: Dict[str, Any],
from_date: str | None = None,
@@ -135,8 +150,15 @@ def parse_linkedin_response(
if not isinstance(post, dict):
continue
+ # The live ScrapeCreators post object carries the body in `description`
+ # and the timestamp in `datePublished`. The other keys are tolerated
+ # fallbacks for shape drift / alternate endpoints.
text = str(
- post.get("text") or post.get("content") or post.get("body") or ""
+ post.get("description")
+ or post.get("text")
+ or post.get("content")
+ or post.get("body")
+ or ""
).strip()
if not text:
continue
@@ -147,10 +169,12 @@ def parse_linkedin_response(
or post.get("author_name")
or ""
)
+ author_url = ""
if isinstance(author_raw, dict):
author = str(
author_raw.get("name") or author_raw.get("full_name") or ""
).strip()
+ author_url = str(author_raw.get("url") or author_raw.get("link") or "").strip()
else:
author = str(author_raw).strip()
@@ -163,7 +187,8 @@ def parse_linkedin_response(
)
date_raw = (
- post.get("date")
+ post.get("datePublished")
+ or post.get("date")
or post.get("postedAt")
or post.get("posted_at")
or post.get("createdAt")
@@ -175,18 +200,21 @@ def parse_linkedin_response(
comments = _int_field(post, "comments", "commentsCount", "comments_count", "numComments", "commentCount")
reposts = _int_field(post, "reposts", "repostsCount", "shares", "shareCount", "reshares")
+ is_article = _is_article(url)
items.append({
"id": post_id,
"text": text,
"url": url,
"author": author,
+ "author_url": author_url,
"date": date,
"engagement": {
"likes": likes,
"comments": comments,
"reposts": reposts,
},
- "relevance": 0.5,
+ "relevance": _ARTICLE_RELEVANCE if is_article else _POST_RELEVANCE,
+ "is_article": is_article,
})
if from_date and to_date:
@@ -200,3 +228,122 @@ def parse_linkedin_response(
_log(f"No posts within date range, keeping all {len(items)}")
return items
+
+
+# --- Article enrichment ---------------------------------------------------
+#
+# LinkedIn articles (Pulse long-form) never appear in /search/posts results —
+# every search hit is a /posts/ status update. Articles live only on the
+# author's profile, under `articles[]`. To honor "an article is high signal"
+# we run a bounded enrichment lane: when a returned post's author name matches
+# the topic (i.e. this is a person topic and we already hold their profile
+# URL), make ONE profile call and surface their articles as high-signal items.
+
+
+def _normalize_name(s: str) -> str:
+ """Lowercase, strip punctuation, collapse whitespace — for name matching."""
+ return re.sub(r"[^a-z0-9]+", " ", (s or "").lower()).strip()
+
+
+def _best_author_match(items: List[Dict[str, Any]], topic: str) -> str:
+ """Return the profile URL of the post author whose name matches the topic.
+
+ Person-topic detection without a global predicate: if one of the returned
+ posts is authored by someone whose (multi-word) name equals or is contained
+ in the topic, treat the topic as being about that person and return their
+ profile URL. Empty string when no confident match — which keeps enrichment
+ off for keyword topics like "AI agents".
+ """
+ topic_norm = _normalize_name(topic)
+ if not topic_norm:
+ return ""
+ for item in items:
+ name = _normalize_name(item.get("author", ""))
+ url = (item.get("author_url") or "").strip()
+ if not url or len(name.split()) < 2:
+ continue
+ if name == topic_norm or name in topic_norm or topic_norm in name:
+ return url
+ return ""
+
+
+def search_profile(profile_url: str, token: str) -> Dict[str, Any]:
+ """Fetch a LinkedIn profile (incl. `articles[]`) via ScrapeCreators."""
+ if not token or not profile_url:
+ return {}
+ url = f"{SC_BASE}/profile?{urlencode({'url': profile_url})}"
+ try:
+ response = http.request(
+ "GET", url, headers={"x-api-key": token}, timeout=30
+ )
+ except http.HTTPError as exc:
+ _log(f"Profile fetch failed (HTTP {exc.status_code}): {exc}")
+ return {}
+ except Exception as exc:
+ _log(f"Profile fetch failed: {type(exc).__name__}: {exc}")
+ return {}
+ return response if isinstance(response, dict) else {}
+
+
+def parse_profile_articles(
+ profile: Dict[str, Any],
+ from_date: str | None = None,
+ to_date: str | None = None,
+) -> List[Dict[str, Any]]:
+ """Map a profile's `articles[]` into high-signal engine item dicts."""
+ articles = profile.get("articles") or []
+ author = str(profile.get("name") or "").strip()
+ items: List[Dict[str, Any]] = []
+
+ for i, art in enumerate(articles):
+ if not isinstance(art, dict):
+ continue
+ headline = str(art.get("headline") or art.get("title") or "").strip()
+ if not headline:
+ continue
+ url = str(art.get("url") or art.get("link") or "").strip()
+ date = _parse_date(art.get("datePublished") or art.get("date"))
+ items.append({
+ "id": str(art.get("id") or f"LIA{i + 1}"),
+ "text": headline,
+ "url": url,
+ "author": author,
+ "date": date,
+ "engagement": {},
+ "relevance": _ARTICLE_RELEVANCE,
+ "is_article": True,
+ })
+
+ if from_date and to_date:
+ in_range = [i for i in items if i["date"] and from_date <= i["date"] <= to_date]
+ if in_range:
+ items = in_range
+ return items
+
+
+def enrich_articles(
+ items: List[Dict[str, Any]],
+ topic: str,
+ token: str,
+ from_date: str | None = None,
+ to_date: str | None = None,
+) -> List[Dict[str, Any]]:
+ """Surface a person's LinkedIn articles as high-signal items.
+
+ Bounded: fires only on person topics (a returned post author matches the
+ topic) and makes at most ONE profile API call. No-ops gracefully when
+ there's no match, no token, no profile, or no articles.
+ """
+ if not token:
+ return []
+ profile_url = _best_author_match(items, topic)
+ if not profile_url:
+ return []
+ _log(f"Person topic — enriching articles from {profile_url}")
+ profile = search_profile(profile_url, token)
+ if not profile:
+ return []
+ articles = parse_profile_articles(profile, from_date=from_date, to_date=to_date)
+ if articles:
+ _log(f"Found {len(articles)} article(s)")
+ return articles
diff --git a/skills/last30days/scripts/lib/normalize.py b/skills/last30days/scripts/lib/normalize.py
index 42f3d59b..958b9a57 100644
--- a/skills/last30days/scripts/lib/normalize.py
+++ b/skills/last30days/scripts/lib/normalize.py
@@ -610,23 +610,32 @@ def _normalize_linkedin(
from_date: str,
to_date: str,
) -> schema.SourceItem:
- """Normalizer for LinkedIn posts via ScrapeCreators."""
+ """Normalizer for LinkedIn posts and articles via ScrapeCreators.
+
+ A LinkedIn article (Pulse long-form, under a /pulse/ URL) is treated as
+ high signal: it ranks above ordinary posts. Detection is belt-and-suspenders
+ — honor the parser's `is_article` flag, and re-derive from the URL so an
+ article still ranks high even if the flag wasn't set upstream.
+ """
text = str(item.get("text") or "").strip()
author = str(item.get("author") or "").strip()
url = str(item.get("url") or "").strip()
+ is_article = bool(item.get("is_article")) or "/pulse/" in url.lower()
+ kind = "article" if is_article else "post"
+ default_relevance = 0.9 if is_article else 0.5
return _source_item(
item_id=str(item.get("id") or f"LI{index + 1}"),
source=source,
- title=text[:140] or f"LinkedIn post {index + 1}",
+ title=text[:140] or f"LinkedIn {kind} {index + 1}",
body=text,
url=url,
author=author,
- container="LinkedIn",
+ container="LinkedIn Article" if is_article else "LinkedIn",
published_at=item.get("date"),
date_confidence=_date_confidence(item, from_date, to_date, default="medium"),
engagement=item.get("engagement") or {},
- relevance_hint=item.get("relevance", 0.5),
+ relevance_hint=item.get("relevance", default_relevance),
why_relevant=str(item.get("why_relevant") or ""),
snippet=text[:200],
- metadata={"author_display": author},
+ metadata={"author_display": author, "is_article": is_article},
)
diff --git a/skills/last30days/scripts/lib/pipeline.py b/skills/last30days/scripts/lib/pipeline.py
index df52fadd..d5f7e7f9 100644
--- a/skills/last30days/scripts/lib/pipeline.py
+++ b/skills/last30days/scripts/lib/pipeline.py
@@ -1411,14 +1411,23 @@ def _retrieve_stream(
)
return instagram.parse_instagram_response(result), {}
if source == "linkedin":
+ token = config.get("SCRAPECREATORS_API_KEY", "")
result = linkedin.search_linkedin(
subquery.search_query,
from_date,
to_date,
depth=depth,
- token=config.get("SCRAPECREATORS_API_KEY", ""),
+ token=token,
)
- return linkedin.parse_linkedin_response(result, from_date=from_date, to_date=to_date), {}
+ items = linkedin.parse_linkedin_response(
+ result, from_date=from_date, to_date=to_date
+ )
+ # Articles never appear in post search — surface them (high signal)
+ # via a bounded profile-enrichment lane on person topics.
+ items += linkedin.enrich_articles(
+ items, raw_topic or topic, token, from_date=from_date, to_date=to_date
+ )
+ return items, {}
if source == "hackernews":
result = hackernews.search_hackernews(subquery.search_query, from_date, to_date, depth=depth)
return hackernews.parse_hackernews_response(result, query=subquery.search_query), {}
diff --git a/tests/test_linkedin.py b/tests/test_linkedin.py
index 56901a63..33c8d7f7 100644
--- a/tests/test_linkedin.py
+++ b/tests/test_linkedin.py
@@ -5,38 +5,60 @@ from lib.linkedin import (
_extract_posts,
_int_field,
_parse_date,
+ enrich_articles,
parse_linkedin_response,
+ parse_profile_articles,
search_linkedin,
)
class TestParseLinkedinResponse(unittest.TestCase):
def _make_post(self, **overrides):
+ # Mirrors the live ScrapeCreators /v1/linkedin/search/posts post object:
+ # body in `description`, timestamp in `datePublished`, author as a nested
+ # dict, engagement in `likeCount`/`commentCount`, comments as a list.
base = {
- "id": "urn:li:activity:123",
- "text": "Excited to share our latest product update.",
"url": "https://www.linkedin.com/posts/example_123",
- "author": "Jane Doe",
- "date": "2026-06-01",
- "likes": 42,
- "comments": 5,
- "reposts": 2,
+ "datePublished": "2026-06-01T12:30:00.000Z",
+ "description": "Excited to share our latest product update.",
+ "author": {
+ "name": "Jane Doe",
+ "url": "https://www.linkedin.com/in/janedoe",
+ "followers": 1234,
+ },
+ "comments": [{"author": "Bob", "text": "nice", "linkedinUrl": "x"}],
+ "likeCount": 42,
+ "commentCount": 5,
}
base.update(overrides)
return base
- def test_basic_post_parses_all_fields(self):
+ def test_real_shape_post_parses_all_fields(self):
items = parse_linkedin_response({"posts": [self._make_post()]})
self.assertEqual(1, len(items))
item = items[0]
- self.assertEqual("urn:li:activity:123", item["id"])
- self.assertEqual("Excited to share our latest product update.", item["text"])
self.assertEqual("https://www.linkedin.com/posts/example_123", item["url"])
+ self.assertEqual("Excited to share our latest product update.", item["text"])
self.assertEqual("Jane Doe", item["author"])
+ self.assertEqual("https://www.linkedin.com/in/janedoe", item["author_url"])
self.assertEqual("2026-06-01", item["date"])
self.assertEqual(42, item["engagement"]["likes"])
self.assertEqual(5, item["engagement"]["comments"])
- self.assertEqual(2, item["engagement"]["reposts"])
+ self.assertFalse(item["is_article"])
+
+ def test_description_and_datepublished_only_parses_nonempty(self):
+ # Regression guard for the exact bug that shipped: the live API uses
+ # `description` + `datePublished`, and a parser keyed on `text`/`date`
+ # dropped every post (10 raw -> 0 items). This must stay non-empty.
+ raw = {
+ "description": "body via description field",
+ "datePublished": "2026-06-10T09:00:00Z",
+ "url": "https://www.linkedin.com/posts/abc",
+ }
+ items = parse_linkedin_response({"posts": [raw]})
+ self.assertEqual(1, len(items))
+ self.assertEqual("body via description field", items[0]["text"])
+ self.assertEqual("2026-06-10", items[0]["date"])
def test_empty_posts_returns_empty_list(self):
self.assertEqual([], parse_linkedin_response({"posts": []}))
@@ -44,7 +66,7 @@ class TestParseLinkedinResponse(unittest.TestCase):
def test_post_without_text_is_skipped(self):
raw = self._make_post()
- del raw["text"]
+ del raw["description"]
items = parse_linkedin_response({"posts": [raw]})
self.assertEqual([], items)
@@ -69,11 +91,17 @@ class TestParseLinkedinResponse(unittest.TestCase):
self.assertEqual("", items[0]["author"])
def test_id_falls_back_to_generated_index(self):
+ # The live post object carries no top-level id/urn; the parser
+ # synthesizes a stable per-index id.
raw = self._make_post()
- del raw["id"]
items = parse_linkedin_response({"posts": [raw]})
self.assertEqual("LI1", items[0]["id"])
+ def test_explicit_urn_used_as_id(self):
+ raw = self._make_post(urn="urn:li:activity:999")
+ items = parse_linkedin_response({"posts": [raw]})
+ self.assertEqual("urn:li:activity:999", items[0]["id"])
+
def test_alternate_field_names(self):
raw = {
"postId": "p1",
@@ -228,5 +256,139 @@ class TestDateRangeFiltering(unittest.TestCase):
self.assertEqual("has date in range", items[0]["text"])
+class TestArticleDetection(unittest.TestCase):
+ def test_pulse_url_tagged_as_article_and_boosted(self):
+ raw = {
+ "description": "long-form piece",
+ "datePublished": "2026-06-10",
+ "url": "https://www.linkedin.com/pulse/wtf-is-a-loop-matt-van-horn-abc",
+ }
+ item = parse_linkedin_response({"posts": [raw]})[0]
+ self.assertTrue(item["is_article"])
+ self.assertEqual(0.9, item["relevance"])
+
+ def test_posts_url_not_article_default_relevance(self):
+ raw = {
+ "description": "ordinary status update",
+ "datePublished": "2026-06-10",
+ "url": "https://www.linkedin.com/posts/example_123",
+ }
+ item = parse_linkedin_response({"posts": [raw]})[0]
+ self.assertFalse(item["is_article"])
+ self.assertEqual(0.5, item["relevance"])
+
+
+class TestProfileArticles(unittest.TestCase):
+ def _profile(self, **overrides):
+ base = {
+ "name": "Matt Van Horn",
+ "articles": [
+ {
+ "headline": "WTF Is a Loop? Part 2",
+ "url": "https://www.linkedin.com/pulse/wtf-loop-part-2-abc",
+ "datePublished": "2026-06-20T21:06:18.000+00:00",
+ "articleBody": "",
+ },
+ {
+ "headline": "Every Agentic Engineering Hack I Know",
+ "url": "https://www.linkedin.com/pulse/every-hack-def",
+ "datePublished": "2026-06-04T02:31:36.000+00:00",
+ "articleBody": "",
+ },
+ ],
+ }
+ base.update(overrides)
+ return base
+
+ def test_articles_parse_as_high_signal(self):
+ items = parse_profile_articles(self._profile())
+ self.assertEqual(2, len(items))
+ for it in items:
+ self.assertTrue(it["is_article"])
+ self.assertEqual(0.9, it["relevance"])
+ self.assertEqual("Matt Van Horn", it["author"])
+ self.assertEqual("WTF Is a Loop? Part 2", items[0]["text"])
+
+ def test_articles_respect_date_range(self):
+ items = parse_profile_articles(
+ self._profile(), from_date="2026-06-15", to_date="2026-06-26"
+ )
+ self.assertEqual(1, len(items))
+ self.assertEqual("WTF Is a Loop? Part 2", items[0]["text"])
+
+ def test_empty_or_missing_articles(self):
+ self.assertEqual([], parse_profile_articles({"name": "X"}))
+ self.assertEqual([], parse_profile_articles({"name": "X", "articles": []}))
+
+ def test_article_without_headline_skipped(self):
+ prof = {"name": "X", "articles": [{"url": "u", "datePublished": "2026-06-10"}]}
+ self.assertEqual([], parse_profile_articles(prof))
+
+
+class TestEnrichArticles(unittest.TestCase):
+ def _person_items(self):
+ # Parsed post items as enrich_articles receives them: a person-topic
+ # search returns posts authored by the subject.
+ return [
+ {"author": "Eric Siu", "author_url": "https://www.linkedin.com/in/ericosiu"},
+ {"author": "Matt Van Horn", "author_url": "https://www.linkedin.com/in/mattvanhorn"},
+ ]
+
+ def test_person_topic_enriches_via_one_profile_call(self):
+ profile = {
+ "name": "Matt Van Horn",
+ "articles": [
+ {"headline": "WTF Is a Loop?", "url": "https://www.linkedin.com/pulse/a", "datePublished": "2026-06-20"},
+ ],
+ }
+ with mock.patch(
+ "lib.linkedin.http.request", return_value=profile
+ ) as mock_request:
+ arts = enrich_articles(
+ self._person_items(), "Matt Van Horn", token="fake",
+ from_date="2026-05-27", to_date="2026-06-26",
+ )
+ self.assertEqual(1, len(arts))
+ self.assertTrue(arts[0]["is_article"])
+ self.assertEqual(0.9, arts[0]["relevance"])
+ # Bounded: exactly one profile call.
+ self.assertEqual(1, mock_request.call_count)
+ # And it fetched the matching author's profile, not the first author.
+ called_url = mock_request.call_args[0][1]
+ self.assertIn("mattvanhorn", called_url)
+
+ def test_keyword_topic_makes_no_profile_call(self):
+ with mock.patch("lib.linkedin.http.request") as mock_request:
+ arts = enrich_articles(
+ self._person_items(), "AI agents", token="fake",
+ from_date="2026-05-27", to_date="2026-06-26",
+ )
+ self.assertEqual([], arts)
+ mock_request.assert_not_called()
+
+ def test_no_token_no_call(self):
+ with mock.patch("lib.linkedin.http.request") as mock_request:
+ arts = enrich_articles(self._person_items(), "Matt Van Horn", token="")
+ self.assertEqual([], arts)
+ mock_request.assert_not_called()
+
+ def test_profile_error_returns_empty(self):
+ from lib import http as http_module
+
+ with mock.patch(
+ "lib.linkedin.http.request",
+ side_effect=http_module.HTTPError("boom", status_code=500),
+ ):
+ arts = enrich_articles(self._person_items(), "Matt Van Horn", token="fake")
+ self.assertEqual([], arts)
+
+ def test_no_author_url_no_call(self):
+ items = [{"author": "Matt Van Horn", "author_url": ""}]
+ with mock.patch("lib.linkedin.http.request") as mock_request:
+ arts = enrich_articles(items, "Matt Van Horn", token="fake")
+ self.assertEqual([], arts)
+ mock_request.assert_not_called()
+
+
if __name__ == "__main__":
unittest.main()