How to convert different rss feed dates with Python so they can be ordered

Trying to make an RSS feed reader using django, feedparser and dateutil

Getting this error: can't compare offset-naive and offset-aware datetimes

I just have five feeds right now. These are the datetimes from the feeds..

Sat, 10 Sep 2022 23:08:59 -0400

Sun, 11 Sep 2022 04:08:30 +0000

Sun, 11 Sep 2022 13:12:18 +0000


Sat, 17 Sep 2022 11:27:15 EDT

I was able to order the first four feeds and then I got the error when I added the last one.

## create a list of lists - each inner list holds entries from a feed
parsed_feeds = [feedparser.parse(url)['entries'] for url in feed_urls]

## put all entries in one list
parsed_feeds2 = [item for feed in parsed_feeds for item in feed]

## sort entries by date
parsed_feeds2.sort(key=lambda x: dateutil.parser.parse(x['published']), reverse=True)

How can I make all the datetimes from the feeds the same so they can be ordered?

Back to Top