Quantcast
Channel: How do I retrieve all RSS entries that are no more than X days old - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How do I retrieve all RSS entries that are no more than X days old

$
0
0

I am using Python and the RSS feedparser module to retrieve RSS entries. However I only want to retrieve a news item if it is no more than x days old.

For example if x=4 then my Python code should not fetch anything four days older than the current date.

Feedparser allows you to scrape the 'published' date for the entry, however it is of type unicode and I don't know how to convert this into a datetime object.

Here is some example input:

date = 'Thu, 29 May 2014 20:39:20 +0000'

Here is what I have tried:

from datetime import datetimedate_object = datetime.strptime(date, '%a, %d %b %Y %H:%M:%S %z')

This is the error I get:

ValueError: 'z' is a bad directive in format '%a, %d %b %Y %H:%M:%S %z'

This is what I hope to do with it:

from datetime import datetimea = datetime(today)b = datetime(RSS_feed_entry_date)>>> a-bdatetime.timedelta(6, 1)(a-b).days6

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images