import feedparser

hitList = []
entries = []
feeds = []
sorted_entries = []
feedfile = open('feeds', 'rw') #The file containing all the feeds

	
	#add feed to the feedfile	
def addFeedToFeedListFile(feed): 
	feedfile.write(feed +"\n") 

def addFeedsFromFileToHitList(): 
	while 1:
		lines = feedfile.readlines(100000)
		if not lines: 
			break
		for line in lines: 
			addFeedToHitList(line)
			
	

def addFeedToHitList(feed): 
	hitList.append(feed)	
	print 'addFeedToHitList'
def pullDownAllFeeds(feed): 
	#pull down all feeds
	#future_calls = [Future(feedparser.parse, rss_url) for rss_url in hitList]
	for rss_url in hitList: 
		entries.append(feedparser.parse(rss_url))
		#print feedparser.parse(rss_url)
	#block until they are all in
	#feeds = [future_obj() for future_obj in future_calls]
	print 'pullDownAllTheFeeds'
		
	#extract the entries from the feed object
def extractEntries():
	for feed in feeds:				
		entries.extend( feed["items"] )
		print 'extractEntries'
		
		
		#sort the entries : Empty method for now	

def sortEntries(): 
		##sorted_entries = sorted(entries, key = lambda entry: entry["date_parsed"])
		##sorted_entries = sorted_entries.reverse() #for most recent entries first
		print 'sortEntries'

#adds all feeds to hit list
addFeedsFromFileToHitList()
pullDownAllFeeds(feeds)
extractEntries() 
sortEntries()
if len(entries) == 0: 
	print "entries is empty"
for k in entries: 
	print k

#print entries[0]
