Download projects/oui-max/tools/rss.py from LevelUp2x/adaptai: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/main/projects/oui-max/tools/rss.py
- Command line
-
hf download hf://datasets/LevelUp2x/adaptai/projects/oui-max/tools/rss.py
-
curl -L -o rss.py https://huggingface.co/datasets/LevelUp2x/adaptai/resolve/main/projects/oui-max/tools/rss.py
1.4 kB
| """ | |
| id: rss | |
| title: RSS/Atom Ingest | |
| author: admin | |
| description: Fetch and parse RSS/Atom feeds; return items with title/link. | |
| version: 0.1.0 | |
| license: Proprietary | |
| """ | |
| import urllib.request | |
| import xml.etree.ElementTree as ET | |
| class Tools: | |
| def fetch(self, feed_url: str, max_items: int = 20) -> dict: | |
| xml = urllib.request.urlopen(feed_url, timeout=20).read() | |
| root = ET.fromstring(xml) | |
| items = [] | |
| # RSS | |
| for it in root.findall(".//item"): | |
| t = it.find("title").text if it.find("title") is not None else "" | |
| link_url = it.find("link").text if it.find("link") is not None else "" | |
| items.append({"title": t or "", "link": link_url or ""}) | |
| if len(items) >= max_items: | |
| break | |
| # Atom | |
| if not items: | |
| ns = "{http://www.w3.org/2005/Atom}" | |
| for e in root.findall(".//" + ns + "entry"): | |
| t = ( | |
| e.find(ns + "title").text | |
| if e.find(ns + "title") is not None | |
| else "" | |
| ) | |
| link_el = e.find(ns + "link") | |
| link_url = link_el.get("href") if link_el is not None else "" | |
| items.append({"title": t or "", "link": link_url or ""}) | |
| if len(items) >= max_items: | |
| break | |
| return {"count": len(items), "items": items} | |