MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / fetch_one_query

Function fetch_one_query

deployments/feishu/daily-push-agent/main.py:264–309  ·  view source on GitHub ↗
(query: str)

Source from the content-addressed store, hash-verified

262 def fetch_one_query(query: str) -> List[Dict]:
263 params = urllib.parse.urlencode({"query": query, "limit": per_query_limit, "fields": fields})
264 url = f"https://api.semanticscholar.org/graph/v1/paper/search?{params}"
265 try:
266 request = urllib.request.Request(
267 url,
268 headers={"User-Agent": "PaperFlow Desktop", "x-api-key": api_key},
269 )
270 with urllib.request.urlopen(request, timeout=20) as response:
271 payload = json.loads(response.read().decode("utf-8"))
272 except Exception as exc:
273 print(f" Semantic Scholar fetch error for {query}: {exc}")
274 return []
275
276 query_papers: List[Dict] = []
277 for item in payload.get("data", []) or []:
278 title = str(item.get("title") or "").strip()
279 if not title:
280 continue
281 published = str(item.get("publicationDate") or "").strip()
282 if published:
283 try:
284 published_date = datetime.strptime(published[:10], "%Y-%m-%d").date()
285 if published_date < min_date or published_date > end_date:
286 continue
287 except ValueError:
288 pass
289 external_ids = item.get("externalIds") or {}
290 authors = [author.get("name", "") for author in item.get("authors", []) or [] if author.get("name")]
291 query_papers.append(
292 {
293 "title": title,
294 "authors": authors,
295 "abstract": item.get("abstract") or "",
296 "arxiv_id": external_ids.get("ArXiv", ""),
297 "doi": external_ids.get("DOI", ""),
298 "url": item.get("url") or "",
299 "paper_url": item.get("url") or "",
300 "source": "semantic_scholar",
301 "venue": item.get("venue") or "Semantic Scholar",
302 "publish_date": published or str(item.get("year") or ""),
303 "categories": ["semantic_scholar", query],
304 "metadata": {"semantic_scholar_query": query, "semantic_scholar_ids": external_ids},
305 }
306 )
307 return query_papers
308
309 papers: List[Dict] = []
310 max_workers = min(_env_positive_int("PAPERFLOW_MAX_CONCURRENCY", default=5), len(queries))
311 with ThreadPoolExecutor(max_workers=max_workers) as executor:
312 futures = [executor.submit(fetch_one_query, query) for query in queries]

Callers

nothing calls this directly

Calls 3

decodeMethod · 0.80
readMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected