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(threads): use 'query' param and cap to 1-2 word queries (#558)

cypres009976b9e4b98fc1
diff --git a/skills/last30days/scripts/lib/threads.py b/skills/last30days/scripts/lib/threads.py
index dc27f67a..ddaa9cfb 100644
--- a/skills/last30days/scripts/lib/threads.py
+++ b/skills/last30days/scripts/lib/threads.py
@@ -29,15 +29,23 @@ def _log(msg: str):
def _extract_core_subject(topic: str) -> str:
- """Extract core subject from verbose query for Threads search."""
+ """Extract core subject from verbose query for Threads search.
+
+ The ScrapeCreators Threads keyword endpoint only returns hits for short
+ (1-2 word) queries; 3+ words or leaked boolean operators (the planner
+ emits "A OR B") return zero. Strip boolean operators and cap to the two
+ most salient words.
+ """
from .query import extract_core_subject
_THREADS_NOISE = frozenset({
'best', 'top', 'good', 'great', 'awesome',
'latest', 'new', 'news', 'update', 'updates',
'trending', 'hottest', 'popular', 'viral',
'practices', 'features', 'recommendations', 'advice',
+ 'or', 'and',
})
- return extract_core_subject(topic, noise=_THREADS_NOISE)
+ core = extract_core_subject(topic, noise=_THREADS_NOISE, max_words=2)
+ return " ".join(core.rstrip("?!.").split()[:2])
def _parse_date(item: Dict[str, Any]) -> Optional[str]:
@@ -154,7 +162,7 @@ def search_threads(
try:
data = http.get(
f"{SCRAPECREATORS_BASE}/search",
- params={"keyword": core_topic},
+ params={"query": core_topic},
headers=http.scrapecreators_headers(token),
timeout=30,
retries=2,
diff --git a/tests/test_threads.py b/tests/test_threads.py
new file mode 100644
index 00000000..20256d21
--- /dev/null
+++ b/tests/test_threads.py
@@ -0,0 +1,25 @@
+"""Tests for Threads source module."""
+
+import unittest
+
+from lib import threads
+
+
+class TestExtractCoreSubject(unittest.TestCase):
+ """Test Threads query preprocessing."""
+
+ def test_caps_verbose_planner_query_to_two_words(self):
+ self.assertEqual(
+ threads._extract_core_subject("AI video tools OR tutorials"),
+ "ai video",
+ )
+
+ def test_caps_all_noise_fallback_to_two_words(self):
+ self.assertEqual(
+ threads._extract_core_subject("best practices and recommendations"),
+ "best practices",
+ )
+
+
+if __name__ == "__main__":
+ unittest.main()