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

Function fetch_custom_rss_papers

deployments/feishu/daily-push-agent/main.py:169–226  ·  view source on GitHub ↗

Fetch user-configured RSS/Atom sources for the desktop offline GUI.

(urls: List[str], limit_per_source: int)

Source from the content-addressed store, hash-verified

167def fetch_custom_rss_papers(urls: List[str], limit_per_source: int) -> List[Dict]:
168 """Fetch user-configured RSS/Atom sources for the desktop offline GUI."""
169 if not urls:
170 return []
171
172 per_feed_limit = max(1, int(math.ceil(limit_per_source / max(1, len(urls)))))
173 namespaces = {
174 "atom": "http://www.w3.org/2005/Atom",
175 "dc": "http://purl.org/dc/elements/1.1/",
176 }
177
178 def fetch_one_feed(feed_url: str) -> List[Dict]:
179 try:
180 request = urllib.request.Request(feed_url, headers={"User-Agent": "PaperFlow Desktop"})
181 with urllib.request.urlopen(request, timeout=20) as response:
182 raw = response.read()
183 root = ET.fromstring(raw)
184 except Exception as exc:
185 print(f" Custom RSS fetch error for {feed_url}: {exc}")
186 return []
187
188 items = root.findall(".//item") or root.findall(".//atom:entry", namespaces)
189 feed_papers: List[Dict] = []
190 for item in items[:per_feed_limit]:
191 title = _strip_html(_xml_text(item, "title", "atom:title"))
192 link = _xml_text(item, "link")
193 if not link:
194 atom_link = item.find("atom:link", namespaces)
195 link = atom_link.get("href", "") if atom_link is not None else ""
196 abstract = _strip_html(_xml_text(item, "description", "summary", "atom:summary", "atom:content"))
197 author = _xml_text(item, "dc:creator", "author", "atom:author/atom:name")
198 published = _parse_feed_date(_xml_text(item, "pubDate", "published", "updated", "atom:published", "atom:updated"))
199 if not title:
200 continue
201 feed_papers.append(
202 {
203 "title": title,
204 "authors": [author] if author else [],
205 "abstract": abstract,
206 "url": link,
207 "paper_url": link,
208 "source": "custom_rss",
209 "venue": feed_url,
210 "publish_date": published,
211 "categories": ["custom_rss"],
212 "metadata": {"feed_url": feed_url},
213 }
214 )
215 return feed_papers
216
217 papers: List[Dict] = []
218 max_workers = min(_env_positive_int("PAPERFLOW_MAX_CONCURRENCY", default=5), len(urls))
219 with ThreadPoolExecutor(max_workers=max_workers) as executor:
220 futures = [executor.submit(fetch_one_feed, feed_url) for feed_url in urls]
221 for future in as_completed(futures):
222 papers.extend(future.result())
223 print(f" Fetched {len(papers)} papers from custom RSS")
224 return papers[:limit_per_source]
225
226

Callers 1

fetch_and_process_papersFunction · 0.85

Calls 1

_env_positive_intFunction · 0.85

Tested by

no test coverage detected