1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
"""GeoRSS feed models."""
from __future__ import annotations
import logging
from georss_client.consts import (
XML_TAG_COPYRIGHT,
XML_TAG_DOCS,
XML_TAG_ENTRY,
XML_TAG_GENERATOR,
XML_TAG_IMAGE,
XML_TAG_ITEM,
XML_TAG_LANGUAGE,
XML_TAG_RIGHTS,
XML_TAG_SUBTITLE,
XML_TAG_TTL,
)
from georss_client.xml_parser.feed_image import FeedImage
from georss_client.xml_parser.feed_item import FeedItem
from georss_client.xml_parser.feed_or_feed_item import FeedOrFeedItem
_LOGGER = logging.getLogger(__name__)
class Feed(FeedOrFeedItem):
"""Represents a feed."""
@property
def subtitle(self) -> str | None:
"""Return the subtitle of this feed."""
return self._attribute_with_text([XML_TAG_SUBTITLE])
@property
def copyright(self) -> str | None:
"""Return the copyright of this feed."""
return self._attribute_with_text([XML_TAG_COPYRIGHT, XML_TAG_RIGHTS])
@property
def rights(self) -> str | None:
"""Return the rights of this feed."""
return self.copyright
@property
def generator(self) -> str | None:
"""Return the generator of this feed."""
return self._attribute_with_text([XML_TAG_GENERATOR])
@property
def language(self) -> str | None:
"""Return the language of this feed."""
return self._attribute([XML_TAG_LANGUAGE])
@property
def docs(self) -> str | None:
"""Return the docs URL of this feed."""
return self._attribute_with_text([XML_TAG_DOCS])
@property
def ttl(self) -> int | None:
"""Return the ttl of this feed."""
return self._attribute([XML_TAG_TTL])
@property
def image(self) -> FeedImage | None:
"""Return the image of this feed."""
image = self._attribute([XML_TAG_IMAGE])
if image:
return FeedImage(image)
return None
@property
def entries(self) -> list[FeedItem]:
"""Return the entries of this feed."""
items = self._attribute([XML_TAG_ITEM, XML_TAG_ENTRY])
entries = []
if items and isinstance(items, list):
entries = [FeedItem(item) for item in items]
else:
# A single item in the feed is not represented as an array.
entries.append(FeedItem(items))
return entries
|