Blake Carver wrote:
> What is this line doing?
> item_date = item.get('created_parsed',
> item.get('date_parsed', ()))
>
> What I *think* it should be doing is something like item_date is equal to
> 'modified_parsed, or 'date_parsed', or 'created_parsed' Am I thinking
> wrong on that?
Nope, you're right. The syntax:
foo.get('key', default)
...is a standard "safe" way of getting the value of key 'key' from the
dictionary 'foo'. If there's no key named 'key', it returns default.
The code above says: "return the value of key 'created_parsed' from the
dictionary 'item', or if that key doesn't exist, return the value of key
'date_parsed' from dict 'item', or if that key doesn't exist, return an
empty tuple. It's a little awkward.
> I'm also unlcear this line, why does this need to be done, and why is it
> failing?
> if isinstance(item_date, time.struct_time) and
> len(item_date) == 9:
This checks that the value we got up above matches the value type
specified, and is actually nine items long. That's strange... the
time.struct_time type itself should always be nine items long, I think.
Checking a local copy of feedparser-3.3 (its download site isn't
responding just now) I don't see the bits you're quoting, and the
strategy for handling these possible values has changed. Is it possible
that the version you're using is older, and that a newer one might fix
things?
-Dan
--
Daniel Chudnov
Yale Center for Medical Informatics
(203) 737-5789
|