crunk-columns is a PESOS style website maker
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

41 lines
1.2 KiB

import random
from datetime import datetime
from feedparser import parse
def parse_single_rss_feed(url, entries, tag_filter):
feed = parse(url)
entrylength = len(entries)
for entrynumber, entry in enumerate(feed.entries):
if tag_filter and not contains_category(entry, tag_filter):
continue
if entry.has_key("title"):
entries[entry.title] = []
entrylist = entries[entry.title]
else:
title = str(entrynumber + entrylength)
entries[title] = []
entrylist = entries[title]
entrylist.append(entry.description)
if entry.has_key("published_parsed"):
entrylist.append(entry.published_parsed)
else:
entrylist.append(datetime.now().timetuple())
return entries
def contains_category(entry, tag_filter):
if not entry.has_key("tags"):
return False
for tag in entry.tags:
if tag.term.lower() == tag_filter.lower():
return True
return False
def parse_rss_feeds(urls, tag_filter):
entries = {}
for url in urls:
entries = parse_single_rss_feed(url, entries, tag_filter)
return entries