dhvcc / rss-parser

typed python RSS parsing module built using xmltodict and pydantic
https://dhvcc.github.io/rss-parser/
GNU General Public License v3.0
40 stars 4 forks source link

Too much data under one exception catch block #35

Closed Astromis closed 1 year ago

Astromis commented 1 year ago

Hi.

Nice parser, glad I found that.

I have an idea to improve the code. You see, when I'm parsing my rss feed, I noticed that enclosure attribute is None, but it actually presented in a tree.

Looked at the code, I saw that user defined attribute placed under exception catch block here.

https://github.com/dhvcc/rss-parser/blob/a13e8faa8676049fc79a539421a8ec57aaeac36b/rss_parser/_parser.py#L124

I think it's not a good idea to join different tags under one block, because it doesn't work unless all tags are presented. In my case there are no itunes:image tag but enclosure is.

As minimum, I suggest moving a processing of enclosure tag in separated if statement before exception like this

if item.hasattr(item, "enclosure"):
        item_dict.update(
                {
                    "enclosure": {
                        "content": "",
                        "attrs": {
                            "url": item.enclosure["url"],
                            "length": item.enclosure["length"],
                            "type": item.enclosure["type"],
                        },
                    }
                }
        )

It is a general solution because I don't know what the item actually is. As I got from the specification, enclosure tag is optional, but if it's presented, it must contain those three fields. It seems that the field presence in itunes tag are completely user-defined, though.

dhvcc commented 1 year ago

Hi, thanks for using this package! To better summarize you may check this comment out https://github.com/dhvcc/rss-parser/issues/34#issuecomment-1368154956

I wrote this a long time ago, so I'm rewriting it right now, I'll try to find more time by the end of the week

Astromis commented 1 year ago

Great, thanks. Looking forward to updates.