Skip to content

Commit

Permalink
V2 alpha release
Browse files Browse the repository at this point in the history
Atom support
Parser renamed to RSSParser
Better datetime parsing
Small file changes
  • Loading branch information
dhvcc committed Feb 21, 2024
1 parent 1143adb commit 8f8d6a3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

## About

`rss-parser` is typed python RSS parsing module built using [pydantic](https://github.com/pydantic/pydantic) and [xmltodict](https://github.com/martinblech/xmltodict)
`rss-parser` is typed python RSS/Atom parsing module built using [pydantic](https://github.com/pydantic/pydantic) and [xmltodict](https://github.com/martinblech/xmltodict)

## Installation

Expand All @@ -32,18 +32,25 @@ poetry build
pip install dist/*.whl
```

## V1 -> V2 migration
- `Parser` class was renamed to `RSSParser`
- Models for RSS-specific schemas were moved from `rss_parser.models` to `rss_parser.models.rss`. Generic types are not touched
- Date parsing was changed a bit, now uses pydantic's `validator` instead of `email.utils`, so the code will produce datetimes better, where it was defaulting to `str` before

## Usage

### Quickstart

**NOTE: For parsing Atom, use `AtomParser`**

```python
from rss_parser import Parser
from rss_parser import RSSParser
from requests import get # noqa

rss_url = "https://rss.art19.com/apology-line"
response = get(rss_url)

rss = Parser.parse(response.text)
rss = RSSParser.parse(response.text)

# Print out rss meta data
print("Language", rss.channel.language)
Expand Down Expand Up @@ -73,7 +80,7 @@ Here we can see that description is still somehow has <p> - this is beacause it'
If you want to customize the schema or provide a custom one - use `schema` keyword argument of the parser

```python
from rss_parser import Parser
from rss_parser import RSSParser
from rss_parser.models import XMLBaseModel
from rss_parser.models.rss import RSS
from rss_parser.models.types import Tag
Expand All @@ -87,7 +94,7 @@ class CustomSchema(RSS, XMLBaseModel):
with open("tests/samples/custom.xml") as f:
data = f.read()

rss = Parser.parse(data, schema=CustomSchema)
rss = RSSParser.parse(data, schema=CustomSchema)

print("RSS", rss.version)
print("Custom", rss.custom)
Expand Down Expand Up @@ -157,7 +164,7 @@ please, use `rss_parser.models.types.only_list.OnlyList` like we did in `Channel
```python
from typing import Optional

from rss_parser.models.item import Item
from rss_parser.models.rss.item import Item
from rss_parser.models.types.only_list import OnlyList
from rss_parser.models.types.tag import Tag
from rss_parser.pydantic_proxy import import_v1_pydantic
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "rss-parser"
version = "1.2.1"
description = "Typed pythonic RSS parser"
version = "2.0.0-alpha"
description = "Typed pythonic RSS/Atom parser"
authors = ["dhvcc <[email protected]>"]
license = "GPL-3.0"
readme = "README.md"
Expand Down
4 changes: 2 additions & 2 deletions rss_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from ._parser import AtomParser, BaseParser, Parser, RSSParser
from ._parser import AtomParser, BaseParser, RSSParser

__all__ = ("BaseParser", "Parser", "AtomParser", "RSSParser")
__all__ = ("BaseParser", "AtomParser", "RSSParser")
13 changes: 0 additions & 13 deletions rss_parser/_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,3 @@ class AtomParser(BaseParser):
class RSSParser(BaseParser):
root_key = "rss"
schema = RSS


class Parser(RSSParser):
@classmethod
def parse(cls, data: str, *, schema: Optional[Type[XMLBaseModel]] = None) -> XMLBaseModel:
import warnings

warnings.warn(
"Class Parser was renamed to RSSParser " "and will be removed in the next major update",
DeprecationWarning,
stacklevel=2,
)
return RSSParser.parse(data, schema=schema)

0 comments on commit 8f8d6a3

Please sign in to comment.