Skip to content

Commit 420a957

Browse files
committed
Changed entrypoint to accomodate Atom and new dir structure
1 parent 7dd857a commit 420a957

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

rss_parser/_parser.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
from typing import ClassVar, Optional, Type
1+
from typing import Optional, Type
22

33
from xmltodict import parse
44

55
from rss_parser.models import XMLBaseModel
6+
from rss_parser.models.atom import Atom
67
from rss_parser.models.rss import RSS
78

89
# >>> FUTURE
910
# TODO: May be support generator based approach for big rss feeds
1011
# TODO: Add cli to parse to json
1112
# TODO: Possibly bundle as deb/rpm/exe
12-
# TODO: Atom support
13-
# TODO: Older RSS versions?
13+
# TODO: Older Atom versions
14+
# TODO: Older RSS versions
1415

1516

1617
class Parser:
1718
"""Parser for rss files."""
1819

19-
schema: ClassVar[Type[XMLBaseModel]] = RSS
20-
2120
@staticmethod
22-
def _check_atom(root: dict):
21+
def check_schema(root: dict) -> tuple[dict, type[XMLBaseModel]]:
2322
if "feed" in root:
24-
raise NotImplementedError("ATOM feed is not currently supported")
23+
return root, Atom
24+
return root["rss"], RSS
2525

2626
@staticmethod
2727
def to_xml(data: str, *args, **kwargs):
@@ -36,8 +36,6 @@ def parse(cls, data: str, *, schema: Optional[Type[XMLBaseModel]] = None) -> XML
3636
:return: "schema" object
3737
"""
3838
root = cls.to_xml(data)
39-
cls._check_atom(root)
40-
41-
schema = schema or cls.schema
39+
root, schema = cls.check_schema(root)
4240

43-
return schema.parse_obj(root["rss"])
41+
return schema.parse_obj(root)

0 commit comments

Comments
 (0)