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

Function parse_rss_2_0

AskAgent/python/data_loading/rss2schema.py:228–379  ·  view source on GitHub ↗

Parse an RSS 2.0 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

226 return candidates[0]
227
228def parse_rss_2_0(root: ET.Element, feed_url: str | None = None) -> list[dict[str, Any]]:
229 """
230 Parse an RSS 2.0 feed into Schema.org format.
231
232 Args:
233 root: XML root element
234 feed_url: URL of the feed
235
236 Returns:
237 List of Schema.org formatted items
238 """
239 result = []
240
241 # Get channel element
242 channel = root.find('channel')
243 if channel is None:
244 print("Warning: No channel element found in RSS feed")
245 return result
246
247 # Extract podcast (feed) information
248 podcast_title = safe_get_text(channel.find('title'))
249 podcast_description = safe_get_text(channel.find('description'))
250 podcast_link = safe_get_text(channel.find('link'))
251 podcast_language = safe_get_text(channel.find('language'))
252
253 # Extract image
254 podcast_image = None
255 image_elem = channel.find('image')
256 if image_elem is not None:
257 image_url = safe_get_text(image_elem.find('url'))
258 if image_url:
259 podcast_image = {"@type": "ImageObject", "url": fix_url(image_url)}
260
261 # iTunes image (higher quality)
262 for ns_prefix, ns_uri in NAMESPACES.items():
263 if ns_prefix == 'itunes':
264 itunes_image = channel.find(f".//{{{ns_uri}}}image")
265 if itunes_image is not None and 'href' in itunes_image.attrib:
266 podcast_image = {"@type": "ImageObject", "url": fix_url(itunes_image.get('href'))}
267
268 # Create basic podcast series schema
269 podcast_series = {
270 "@type": "PodcastSeries",
271 "name": podcast_title,
272 "description": podcast_description,
273 "url": fix_url(podcast_link) or feed_url or ""
274 }
275
276 if podcast_image:
277 podcast_series["image"] = podcast_image
278
279 if podcast_language:
280 podcast_series["inLanguage"] = podcast_language
281
282 # Process each item (episode)
283 for item in channel.findall('item'):
284 try:
285 # Basic fields

Callers 1

feed_to_schemaFunction · 0.85

Calls 6

safe_get_textFunction · 0.85
fix_urlFunction · 0.85
extract_best_urlFunction · 0.85
extract_guidFunction · 0.85
extract_durationFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected