# Simple hack to merge RSS feeds

Have I made any obvious mistakes?
Is this code clean?
Is there a better way to do this in python?

# -*- coding: utf-8 -*-
import feedparser
from feedgen.feed import FeedGenerator
from random import shuffle
from feedformatter import Feed
import time
from datetime import datetime

tstart = datetime.now()
# Set the feed/channel level properties
# ----------------------------------- #
chanTitle = 'Feed Merger'
chanAuthor = 'Bob Dylan'
chanDescription = 'Brain Food'
# ----------------------------------- #
# Apply feed/channel level properties
# ----------------------------------- #
feed = Feed()
feed.feed["title"] = chanTitle
feed.feed["author"] = chanAuthor
feed.feed["description"] = chanDescription
# ----------------------------------- #
shuffle(urls)
extract_entries = lambda url: feedparser.parse(url).entries
addEntries = lambda entries: [feed.items.append(entry) for entry in entries]
merg = lambda urls: [addEntries(extract_entries(url)) for url in urls]
shuffle(feed.entries)
merg(urls)
save('feed.xml')
tend = datetime.now()
runtime = tend - tstart
print "Runtime > %s" % (runtime)
print "Merged  > %d items" % (len(feed.entries))

• While the objective of this site is quite clear, it is always nice when askers give some more context than just the pure code to review. For example, you could highlight parts of the code that you want special reviews for or guide the general direction of the review(e.g.: "I want tips on performance improvements" or "Improve my naming"). Apr 18 '14 at 18:22

These lines appear to be out of order:

extract_entries = lambda url: feedparser.parse(url).entries
addEntries = lambda entries: [feed.items.append(entry) for entry in entries]
merg = lambda urls: [addEntries(extract_entries(url)) for url in urls]
shuffle(feed.entries)
merg(urls)


In particular, when that shuffle runs, the feed has no entries yet, so there's nothing to shuffle. I think you meant this way:

extract_entries = lambda url: feedparser.parse(url).entries
addEntries = lambda entries: [feed.items.append(entry) for entry in entries]
merg = lambda urls: [addEntries(extract_entries(url)) for url in urls]
merg(urls)
shuffle(feed.entries)


More importantly, I think you're overusing lambdas for no benefit at all. The flow of the logic would be a lot easier to read if you used loops instead:

urls = list(set(open('urls.txt', 'r').readlines()))
shuffle(urls)
for url in urls:
for entry in feedparser.parse(url).entries:
feed.items.append(entry)
shuffle(feed.entries)