Parse Atom XML feed into list of entry dicts.
(self, content: bytes)
| 1787 | return None |
| 1788 | |
| 1789 | def _parse_atom(self, content: bytes) -> list[dict]: |
| 1790 | """Parse Atom XML feed into list of entry dicts.""" |
| 1791 | results = [] |
| 1792 | try: |
| 1793 | root = ET.fromstring(content) |
| 1794 | ns = {"atom": "http://www.w3.org/2005/Atom"} |
| 1795 | for entry in root.findall("atom:entry", ns): |
| 1796 | eid_el = entry.find("atom:id", ns) |
| 1797 | title_el = entry.find("atom:title", ns) |
| 1798 | updated_el = entry.find("atom:updated", ns) |
| 1799 | summary_el = entry.find("atom:summary", ns) |
| 1800 | link_el = entry.find("atom:link[@rel='alternate']", ns) |
| 1801 | if link_el is None: |
| 1802 | link_el = entry.find("atom:link", ns) |
| 1803 | |
| 1804 | results.append({ |
| 1805 | "id": eid_el.text.strip() if eid_el is not None and eid_el.text else "", |
| 1806 | "title": title_el.text.strip() if title_el is not None and title_el.text else "", |
| 1807 | "updated": updated_el.text.strip() if updated_el is not None and updated_el.text else "", |
| 1808 | "summary": (summary_el.text or "").strip() if summary_el is not None else "", |
| 1809 | "link": link_el.get("href", "") if link_el is not None else "", |
| 1810 | }) |
| 1811 | except ET.ParseError as e: |
| 1812 | print(f" ERROR parsing Atom XML: {e}") |
| 1813 | return results |
| 1814 | |
| 1815 | |
| 1816 | # --------------------------------------------------------------------------- |