Skip to content

Commit 3130ca1

Browse files
committed
Rename RSSFeed->RSS, RSSBaseModel->XMLBaseModel
Update TODOs
1 parent 8f763d5 commit 3130ca1

File tree

9 files changed

+28
-27
lines changed

9 files changed

+28
-27
lines changed

rss_parser/_parser.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
from xmltodict import parse
22

3-
from rss_parser.models.root import RSSFeed
3+
from rss_parser.models.root import RSS
44

55
# >>> FUTURE
6-
# TODO: Feature, ignore_attributes in to_dict to allow for clean output
76
# TODO: May be support generator based approach for big rss feeds
87
# TODO: Add cli to parse to json
98
# TODO: Possibly bundle as deb/rpm/exe
9+
# TODO: Atom support
10+
# TODO: Older RSS versions?
1011

1112
# >>>> MVP
12-
# TODO: class based approach, use classmethods and class attributes
13+
# TODO: Parser class based approach, use classmethods and class attributes
1314
# TODO: Also add dynamic class generator with config.
1415
# Parser.with_config which returns new class and also supports context managers
15-
# TODO: Limit, xml, schema can be set in config or in runtime
1616
class Parser:
1717
"""Parser for rss files."""
1818

19-
def __init__(self, xml: str, limit=None, *, schema=RSSFeed):
19+
def __init__(self, xml: str, limit=None, *, schema=RSS):
2020
self.xml = xml
2121
self.limit = limit
2222

@@ -28,9 +28,9 @@ def __init__(self, xml: str, limit=None, *, schema=RSSFeed):
2828
@staticmethod
2929
def _check_atom(root: dict):
3030
if "feed" in root:
31-
raise NotImplementedError("ATOM feed is not currently supported") #
31+
raise NotImplementedError("ATOM feed is not currently supported")
3232

33-
def parse(self) -> RSSFeed:
33+
def parse(self) -> RSS:
3434
"""
3535
Parse the rss and each item.py of the feed.
3636

rss_parser/models/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from rss_parser.models.utils import camel_case
1212

1313

14-
class RSSBaseModel(BaseModel):
14+
class XMLBaseModel(BaseModel):
1515
class Config:
1616
# Not really sure if we want for the schema obj to be immutable, disabling for now
1717
# allow_mutation = False

rss_parser/models/channel.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
from pydantic import Field
44

5-
from rss_parser.models import RSSBaseModel
5+
from rss_parser.models import XMLBaseModel
66
from rss_parser.models.image import Image
77
from rss_parser.models.item import Item
88
from rss_parser.models.text_input import TextInput
99
from rss_parser.models.types.date import DateTimeOrStr
1010
from rss_parser.models.types.tag import Tag
1111

1212

13-
class RequiredChannelElementsMixin(RSSBaseModel):
13+
class RequiredChannelElementsMixin(XMLBaseModel):
1414
"""https://www.rssboard.org/rss-specification#requiredChannelElements."""
1515

1616
title: Tag[str] = None # GoUpstate.com News Headlines
@@ -23,7 +23,7 @@ class RequiredChannelElementsMixin(RSSBaseModel):
2323
"Phrase or sentence describing the channel."
2424

2525

26-
class OptionalChannelElementsMixin(RSSBaseModel):
26+
class OptionalChannelElementsMixin(XMLBaseModel):
2727
"""https://www.rssboard.org/rss-specification#optionalChannelElements."""
2828

2929
items: Optional[List[Tag[Item]]] = Field(alias="item", default=[])
@@ -55,7 +55,6 @@ class OptionalChannelElementsMixin(RSSBaseModel):
5555
docs: Optional[Tag[str]] = None # https://www.rssboard.org/rss-specification
5656
"A URL that points to the documentation for the format used in the RSS file. It's probably a pointer to this " "page. It's for people who might stumble across an RSS file on a Web server 25 years from now and wonder what " "it is." # noqa
5757

58-
# TODO: should support self-closing tags with their attributes?
5958
cloud: Optional[Tag[str]] = None # <cloud domain="rpc.sys.com" protocol="soap"/>
6059
"Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight " "publish-subscribe protocol for RSS feeds." # noqa
6160

@@ -78,5 +77,5 @@ class OptionalChannelElementsMixin(RSSBaseModel):
7877
"A hint for aggregators telling them which days they can skip. This element contains up to seven <day> " "sub-elements whose value is Monday, Tuesday, Wednesday, Thursday, Friday, Saturday or Sunday. Aggregators " "may not read the channel during days listed in the <skipDays> element." # noqa
7978

8079

81-
class Channel(RequiredChannelElementsMixin, OptionalChannelElementsMixin, RSSBaseModel):
80+
class Channel(RequiredChannelElementsMixin, OptionalChannelElementsMixin, XMLBaseModel):
8281
pass

rss_parser/models/image.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Optional
22

3-
from rss_parser.models import RSSBaseModel
3+
from rss_parser.models import XMLBaseModel
44
from rss_parser.models.types.tag import Tag
55

66

7-
class Image(RSSBaseModel):
7+
class Image(XMLBaseModel):
88
"""https://www.rssboard.org/rss-specification#ltimagegtSubelementOfLtchannelgt."""
99

1010
url: Tag[str] = None

rss_parser/models/item.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import Optional
22

3-
from rss_parser.models import RSSBaseModel
3+
from rss_parser.models import XMLBaseModel
44
from rss_parser.models.types.tag import Tag
55

66

7-
class RequiredItemElementsMixin(RSSBaseModel):
7+
class RequiredItemElementsMixin(XMLBaseModel):
88
title: Tag[str] = None # Venice Film Festival Tries to Quit Sinking
99
"The title of the item."
1010

@@ -18,7 +18,7 @@ class RequiredItemElementsMixin(RSSBaseModel):
1818
"The item synopsis."
1919

2020

21-
class OptionalItemElementsMixin(RSSBaseModel):
21+
class OptionalItemElementsMixin(XMLBaseModel):
2222
author: Optional[Tag[str]] = None
2323
"Email address of the author of the item."
2424

@@ -41,5 +41,5 @@ class OptionalItemElementsMixin(RSSBaseModel):
4141
"The RSS channel that the item came from."
4242

4343

44-
class Item(RequiredItemElementsMixin, OptionalItemElementsMixin, RSSBaseModel):
44+
class Item(RequiredItemElementsMixin, OptionalItemElementsMixin, XMLBaseModel):
4545
"""https://www.rssboard.org/rss-specification#hrelementsOfLtitemgt."""

rss_parser/models/root.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
from pydantic import Field
44

5-
from rss_parser.models import RSSBaseModel
5+
from rss_parser.models import XMLBaseModel
66
from rss_parser.models.channel import Channel
77
from rss_parser.models.types.tag import Tag
88

99

10-
class RSSFeed(RSSBaseModel):
10+
class RSS(XMLBaseModel):
11+
"""RSS 2.0."""
12+
1113
version: Optional[Tag[str]] = Field(alias="@version")
1214
channel: Tag[Channel]

rss_parser/models/text_input.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from rss_parser.models import RSSBaseModel
1+
from rss_parser.models import XMLBaseModel
22
from rss_parser.models.types.tag import Tag
33

44

5-
class TextInput(RSSBaseModel):
5+
class TextInput(XMLBaseModel):
66
"""
77
The purpose of the <textInput> element is something of a mystery. You can use it to specify a search engine box.
88
Or to allow a reader to provide feedback. Most aggregators ignore it.

rss_parser/models/types/tag.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pydantic.generics import GenericModel
1010
from pydantic.json import pydantic_encoder
1111

12-
from rss_parser.models import RSSBaseModel
12+
from rss_parser.models import XMLBaseModel
1313

1414
T = TypeVar("T")
1515

@@ -68,7 +68,7 @@ def pre_convert(cls, v: Union[T, dict], **kwargs): # noqa
6868
def flatten_tag_encoder(cls, v):
6969
"""Encoder that translates Tag objects (dict) to plain .content values (T)."""
7070
bases = v.__class__.__bases__
71-
if RSSBaseModel in bases:
71+
if XMLBaseModel in bases:
7272
# Can't pass encoder to .dict :/
7373
return loads(v.json_plain())
7474
if cls in bases:

tests/test_tag.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from random import randint
55
from typing import Optional
66

7-
from rss_parser.models import RSSBaseModel
7+
from rss_parser.models import XMLBaseModel
88
from rss_parser.models.types.tag import Tag
99

1010

11-
class Model(RSSBaseModel):
11+
class Model(XMLBaseModel):
1212
number: Optional[Tag[int]]
1313
float_number: Optional[Tag[float]]
1414
string: Optional[Tag[str]]

0 commit comments

Comments
 (0)