Print

Print


Hi All,

Working up a new version of LISFeeds and trying to use Python. I'm not
much of a Python guy so I'm having no luck trying to figure something out.
It's a script that uses the "Universal Feed Parser" to parse RSS feeds
into some MySQL tables.

I think there's a bit of a bug with how dates of feed items are stored,
but I'm not sure, and I can't seem to work well with Python enough to
really debug it very well.


The feeds I run usually have the date/time of an item in
'modified_parsed' (from "Universal Feed Parser"), but, according to the
feed parser docs, dates can be in  'modified_parsed, or 'date_parsed', or
'created_parsed' depending on the type of feed.
So essentially the item_date variable in the below code snippet could be
any of those three items coming from the feed parser.

They should all look something like:  (2004, 12, 6, 12, 3, 32, 0, 341, 0)
That is 'modified_parsed, or 'date_parsed', or 'created_parsed' should all
come into this code area looking something like (2004, 12, 6, 12, 3, 32,
0, 341, 0), so that's what we have to work with. item_date should be
coming from one of those three places, so it needs to do some OR checking
I think.

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?

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:

That seems to be failing everytime, so esstinally date is always equal to
time.strftime("%Y-%m-%d %H:%M:%S") which is always now, not when this item
was posted to that blog.

So what I think should be happening in this little piece of code, is
something like this:

for item in entries
item_date is equal to 'modified_parsed, or 'date_parsed', or 'created_parsed'
if none of those, then just set it to now


here's the code in question:

            for item in data['entries']:
                item_date = item.get('created_parsed',
item.get('date_parsed', ()))
                if isinstance(item_date, time.struct_time) and
len(item_date) == 9:
                    date = time.strftime("%Y-%m-%d %H:%M-%S", item_date)
                else:
                    date = time.strftime("%Y-%m-%d %H:%M:%S")


For the really motivated, simple aggregator is here:
http://www.asiatica.org/~ludo/SimpleAggregator/

and  Universal Feed Parser is here:
http://sourceforge.net/projects/feedparser/


Thanks!

-Blake Carver