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.

42 lines
1.2 KiB

1 year ago
import random
from datetime import datetime
1 year ago
from feedparser import parse
1 year ago
def parse_single_rss_feed(url, entries, tag_filter):
1 year ago
feed = parse(url)
entrylength = len(entries)
1 year ago
for entrynumber, entry in enumerate(feed.entries):
1 year ago
if tag_filter and not contains_category(entry, tag_filter):
continue
1 year ago
if entry.has_key("title"):
entries[entry.title] = []
entrylist = entries[entry.title]
else:
title = str(entrynumber + entrylength)
1 year ago
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())
1 year ago
return entries
1 year ago
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
1 year ago
def parse_rss_feeds(urls, tag_filter):
1 year ago
entries = {}
for url in urls:
1 year ago
entries = parse_single_rss_feed(url, entries, tag_filter)
1 year ago
return entries