HaveF / feedparser

Automatically exported from code.google.com/p/feedparser
Other
0 stars 0 forks source link

"date" attribute not in 5.1.1 #340

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Try to read "date" attribute of an entry with Feedparser 5.1.1 

What is the expected output? What do you see instead?

Traceback from previously working program:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\messager\newsfeed.py", line 181, in fetchitems
    msgitem = self.doentry(entry, now)        # do this entry
  File "C:\Python27\lib\site-packages\messager\newsfeed.py", line 210, in doentry
    date = entry.date                               # date of entry
  File "build\bdist.win32\egg\feedparser.py", line 423, in __getattr__
    raise AttributeError, "object has no attribute '%s'" % key

What version of the product are you using? On what operating system?

Python 2.7, feedparser 5.1.1.

Please provide any additional information below.

Problem does not occur with Feedparser 5.1 or earlier. 

Original issue reported on code.google.com by na...@animats.com on 7 Apr 2012 at 2:12

GoogleCodeExporter commented 9 years ago
Can you point me to a feed that's exhibiting this behavior?

Original comment by kurtmckee on 7 Apr 2012 at 6:48

GoogleCodeExporter commented 9 years ago
The feed used was

http://feeds.reuters.com/reuters/topNews?format=xml

which works fine with older versions of Feedparser.

Original comment by na...@animats.com on 7 Apr 2012 at 4:11

GoogleCodeExporter commented 9 years ago
This is due to a change in how the RSS element `pubDate` is stored in the 
dictionary returned by feedparser. It used to be that `pubDate` mapped to the 
`updated` key. However, `pubDate` represents when something was published, not 
when it was updated. Consequently, `pubDate` maps to `published` now.

I guess as a convenience, `date` is automatically mapped to `updated` behind 
the scenes. However, the information you're looking for is no longer in 
`updated`: it's in `published`.

You'll need to update your code (or file a bug with the software you're using) 
to check for `published` or `updated` as necessary. I recommend avoiding `date` 
entirely.

Original comment by kurtmckee on 7 Apr 2012 at 4:45

GoogleCodeExporter commented 9 years ago
See

http://packages.python.org/feedparser/common-rss-elements.html

which claims to be the documentation for feedparser 5.1.1.

Accessing Common Item Elements (example)
...
>>> d.entries[0].date

Status: Developer in Denial.
Suggested workaround:

    try :                                       # feedparser >= 5.1.1
        date = entry.published                  # publication date of entry
        dateparsed = entry.published_parsed     # date parsed
    except AttributeError:                      # older feedparser
        date = entry.date                       # feedparser < 5.1.1
        dateparsed = entry.date_parsed

Original comment by na...@animats.com on 7 Apr 2012 at 5:20

GoogleCodeExporter commented 9 years ago
Oh snap, good catch! I'll update the documentation when I have an opportunity. 
Thanks, John!

Original comment by kurtmckee on 9 Apr 2012 at 4:22