MCPcopy Create free account
hub / github.com/nlweb-ai/NLWeb / parse_atom

Function parse_atom

AskAgent/python/data_loading/rss2schema.py:381–497  ·  view source on GitHub ↗

Parse an Atom feed into Schema.org format. Args: root: XML root element feed_url: URL of the feed Returns: List of Schema.org formatted items

(root: ET.Element, feed_url: str | None = None)

Source from the content-addressed store, hash-verified

379 return result
380
381def parse_atom(root: ET.Element, feed_url: str | None = None) -> list[dict[str, Any]]:
382 """
383 Parse an Atom feed into Schema.org format.
384
385 Args:
386 root: XML root element
387 feed_url: URL of the feed
388
389 Returns:
390 List of Schema.org formatted items
391 """
392 result = []
393 ns = {"atom": "http://www.w3.org/2005/Atom"}
394
395 # Extract feed information
396 feed_title = safe_get_text(root.find('atom:title', ns))
397 feed_subtitle = safe_get_text(root.find('atom:subtitle', ns))
398
399 # Extract feed link
400 feed_link = feed_url
401 for link in root.findall('atom:link', ns):
402 rel = link.get('rel', 'alternate')
403 if rel == 'self' and not feed_link:
404 feed_link = link.get('href')
405 elif rel == 'alternate':
406 feed_link = link.get('href')
407 break
408
409 feed_link = fix_url(feed_link or "")
410
411 # Create podcast series schema
412 podcast_series = {
413 "@type": "PodcastSeries",
414 "name": feed_title,
415 "description": feed_subtitle,
416 "url": feed_link
417 }
418
419 # Process each entry
420 for entry in root.findall('atom:entry', ns):
421 try:
422 # Basic fields
423 title = safe_get_text(entry.find('atom:title', ns))
424 summary = safe_get_text(entry.find('atom:summary', ns))
425 published = safe_get_text(entry.find('atom:published', ns))
426 updated = safe_get_text(entry.find('atom:updated', ns))
427
428 # Extract link (URL)
429 entry_url = None
430 for link in entry.findall('atom:link', ns):
431 rel = link.get('rel', 'alternate')
432 if rel == 'alternate':
433 entry_url = link.get('href')
434 break
435
436 if not entry_url:
437 # Try any link
438 for link in entry.findall('atom:link', ns):

Callers 1

feed_to_schemaFunction · 0.85

Calls 3

safe_get_textFunction · 0.85
fix_urlFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected