From 7fa3850a665a7d5ee78d1e38f22a9bb29ded6bc8 Mon Sep 17 00:00:00 2001 From: Adam Sampson Date: Sat, 12 Jul 2003 17:06:44 +0000 Subject: [PATCH] Support the Echo content element by selecting the most appropriate one. --- rawdoglib/rawdog.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/rawdoglib/rawdog.py b/rawdoglib/rawdog.py index 50b643e..159b6b3 100644 --- a/rawdoglib/rawdog.py +++ b/rawdoglib/rawdog.py @@ -26,6 +26,21 @@ def format_time(secs, config): t = time.localtime(secs) return time.strftime(config["timeformat"], t) + ", " + time.strftime(config["dayformat"], t) +def select_content(contents): + """Select the best content element from an Echo feed.""" + preferred = ["text/html", "application/xhtml+xml"] + cs = [] + for c in contents: + type = c["type"] + if type in preferred: + score = preferred.index(type) + cs.append((score, c["value"])) + cs.sort() + if len(cs) == 0: + return None + else: + return cs[0][1] + class Feed: """An RSS feed.""" @@ -73,6 +88,8 @@ class Feed: link = item.get("link") if item.has_key("content_encoded"): description = item["content_encoded"] + elif item.has_key("content"): + description = select_content(item["content"]) else: description = item.get("description") -- 2.35.1