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.
35 lines
1.0 KiB
35 lines
1.0 KiB
import random
|
|
|
|
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)
|
|
entrylist.append(entry.published_parsed)
|
|
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
|
|
|