Make a smarter choice for -a when multiple feeds are available.
authorAdam Sampson <ats@offog.org>
Sat, 19 Mar 2011 12:10:21 +0000 (12:10 +0000)
committerAdam Sampson <ats@offog.org>
Sat, 19 Mar 2011 12:10:21 +0000 (12:10 +0000)
NEWS
rawdoglib/rawdog.py

diff --git a/NEWS b/NEWS
index f317a7c6d81feedfaa3bc364e54bed984b0de461..aad4705eb3769c73a5c36d2eb5fa5c567f341e1a 100644 (file)
--- 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
index 172fc842a1c124007d9f8503b9dcfe4253311a89..51e55cc5210bfbf5a248932b7ee9161da6d0db89 100644 (file)
@@ -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