def atom_document_to_feed(atom_url: str, tree: ElementBase) -> Feed: title = tree.findtext("{http://www.w3.org/2005/Atom}title") description = tree.findtext("{http://www.w3.org/2005/Atom}subtitle") category = tree.findtext("{http://www.w3.org/2005/Atom}category") link = tree.findtext("{http://www.w3.org/2005/Atom}link") or atom_url return Feed( url=atom_url, title=title, link=link, description=description, category=category, feed_source_type=FeedSourceType.ATOM, )
def rss_document_to_feed(rss_url: str, tree: ElementBase) -> Feed: # required rss channel items title = tree.findtext("channel/title") description = parse_description(tree.findtext("channel/description")) link = tree.findtext("channel/link") # optional rss channel items category = tree.find("channel/category") image_url = tree.find("channel/image/url") image_title = tree.find("channel/image/title") image_link = tree.find("channel/image/link") return Feed( url=rss_url.rstrip("/"), title=title, description=description, link=link, feed_source_type=FeedSourceType.RSS, category=category.text if category is not None else None, image_url=image_url.text if image_url is not None else None, image_title=image_title.text if image_title is not None else None, image_link=image_link.text if image_link is not None else None, )
def rdf_document_to_feed(rss_url: str, tree: ElementBase) -> Feed: # required rss channel items title = tree.findtext("{*}channel/{*}title") description = parse_description(tree.findtext("{*}channel/{*}description")) link = tree.findtext("{*}channel/{*}link") # optional rss channel items category = tree.find("{*}channel/{*}category") image_tag = tree.find("{*}channel/{*}image") image_url = ( image_tag.get("{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource") if image_tag is not None else None) return Feed( url=rss_url.rstrip("/"), title=title, description=description, link=link, feed_source_type=FeedSourceType.RDF, category=category.text if category is not None else None, image_url=image_url if image_url is not None else None, image_title=None, image_link=None, )