From ea374de1b2f9a750681e4e7002fd654362a5a44a Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sat, 19 Mar 2011 12:10:21 +0000 Subject: [PATCH] Make a smarter choice for -a when multiple feeds are available. --- NEWS | 5 +++++ rawdoglib/rawdog.py | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index f317a7c..aad4705 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ - rawdog 2.14 +When adding a new feed from a page that provides several feeds, make a +more informed choice rather than just taking the first one: many blogs +provide both content and comments feeds, and we usually want the first +one. + - rawdog 2.13 Forcibly disable BeautifulSoup support in feedparser, since it returns diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 172fc84..51e55cc 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -902,7 +902,20 @@ def add_feed(filename, url, rawdog, config): print >>sys.stderr, "Cannot find any feeds in " + url return - feed = feeds[0] + # Sort feeds into preference order: some sites provide feeds for + # content and comments, or both Atom and RSS. + part_scores = {"comment": -10, + "atom": 2} + scored = [] + for feed in feeds: + score = 0 + for p, s in part_scores.items(): + if feed.find(p) != -1: + score += s + scored.append((-score, feed)) + scored.sort() + + feed = scored[0][1] if feed in rawdog.feeds: print >>sys.stderr, "Feed " + feed + " is already in the config file" return -- 2.35.1