NicolasLM / atoma

Atom, RSS and JSON feed parser for Python 3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON Feed version 1.0 author field cause AttributeError

guyskk opened this issue · comments

commented

feed url: https://hnrss.org/newest.jsonfeed
feed content: newest.txt

  File "/Users/kk/.pyenv/versions/rssant377/lib/python3.7/site-packages/atoma/json_feed.py", line 201, in parse_json_feed
    items=_get_items(root)
  File "/Users/kk/.pyenv/versions/rssant377/lib/python3.7/site-packages/atoma/json_feed.py", line 74, in _get_items
    rv.append(_get_item(item))
  File "/Users/kk/.pyenv/versions/rssant377/lib/python3.7/site-packages/atoma/json_feed.py", line 92, in _get_item
    author=_get_author(item_dict),
  File "/Users/kk/.pyenv/versions/rssant377/lib/python3.7/site-packages/atoma/json_feed.py", line 137, in _get_author
    name=_get_text(author_dict, 'name'),
  File "/Users/kk/.pyenv/versions/rssant377/lib/python3.7/site-packages/atoma/json_feed.py", line 173, in _get_text
    rv = root.get(name)
AttributeError: 'str' object has no attribute 'get'

Expect to compatible with 1.0 author field, although it's deprecated.

https://jsonfeed.org/version/1.1

Deprecated items remain valid forever, but you should move to the new fields when you can. A feed using fields from JSON Feed 1.0 is still a valid feed for version 1.1 and future versions of JSON Feed.

And thank you for the handy library! I'm also glad to create PR to fix it if you don't have time, just tell me go ahead.

Hi, it doesn't seem to be a problem of JSON Feed 1.0 vs 1.1, but rather the fact that the feed you linked uses author as a string when it should be an object:

For JSON Feed v1.0:

{
    "author": {
        "name": "Brent Simmons",
        "url": "http://example.org/",
        "avatar": "https://example.org/avatar.png"
    }
}

For JSON Feed v1.1:

{
    "authors": [{
        "name": "Brent Simmons",
        "url": "http://example.org/",
        "avatar": "https://example.org/avatar.png"
    }]
}

Dealing with malformed feeds is always a balancing act. Here I would say that hnrss.org should fix their feed instead of dealing with the mistake in Atoma.

I filled an issue: hnrss/hnrss#43

commented

Got it, thank you!