From 5d7bd64342f45aa74a7a5f951b90e630cccf917d Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Sun, 3 Sep 2006 08:52:09 -0400 Subject: [PATCH] Activity threshold and http status messages --- examples/opml-top100.ini | 7 +++-- planet/config.py | 1 + planet/spider.py | 26 +++++++++++++++++++ .../filter/tmpl/source_planet_message.xml | 16 ++++++++++++ themes/asf/index.html.xslt | 13 ++++++++++ 5 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 tests/data/filter/tmpl/source_planet_message.xml diff --git a/examples/opml-top100.ini b/examples/opml-top100.ini index 34abd64..0522472 100644 --- a/examples/opml-top100.ini +++ b/examples/opml-top100.ini @@ -1,6 +1,4 @@ # Planet configuration file -# -# This illustrates some of Planet's fancier features with example. # Every planet needs a [Planet] section [Planet] @@ -26,13 +24,18 @@ output_theme = mobile output_dir = /home/rubys/public_html/top100 items_per_page = 60 +# If non-zero, all feeds which have not been updated in the indicated +# number of days will be marked as inactive activity_threshold = 90 +# filters to be run filters = excerpt.py +# filter parameters [excerpt.py] omit = img p br width = 500 +# subscription list [http://share.opml.org/opml/top100.opml] content_type = opml diff --git a/planet/config.py b/planet/config.py index 6679abc..7ea0a00 100644 --- a/planet/config.py +++ b/planet/config.py @@ -107,6 +107,7 @@ def __init__(): # template options define_tmpl_int('days_per_page', 0) define_tmpl_int('items_per_page', 60) + define_tmpl_int('activity_threshold', 0) define_tmpl('encoding', 'utf-8') define_tmpl('content_type', 'utf-8') diff --git a/planet/spider.py b/planet/spider.py index a1ee5c4..8c24d32 100644 --- a/planet/spider.py +++ b/planet/spider.py @@ -110,6 +110,32 @@ def spiderFeed(feed): for name, value in config.feed_options(feed).items(): data.feed['planet_'+name] = value + # identify inactive feeds + if config.activity_threshold(feed): + activity_horizon = \ + time.gmtime(time.time()-86400*config.activity_threshold(feed)) + updated = [entry.updated_parsed for entry in data.entries + if entry.has_key('updated_parsed')] + updated.sort() + if not updated or updated[-1] < activity_horizon: + msg = "no activity in %d days" % config.activity_threshold(feed) + log.info(msg) + data.feed['planet_message'] = msg + + # report channel level errors + if data.status == 403: + data.feed['planet_message'] = "403: forbidden" + elif data.status == 404: + data.feed['planet_message'] = "404: not found" + elif data.status == 408: + data.feed['planet_message'] = "408: request timeout" + elif data.status == 410: + data.feed['planet_message'] = "410: gone" + elif data.status == 500: + data.feed['planet_message'] = "internal server error" + elif data.status >= 400: + data.feed['planet_message'] = "http status %s" % status + # write the feed info to the cache if not os.path.exists(sources): os.makedirs(sources) xdoc=minidom.parseString(''' + + + + + foo + + + + foo + + + diff --git a/themes/asf/index.html.xslt b/themes/asf/index.html.xslt index 5474a9f..e314ab1 100644 --- a/themes/asf/index.html.xslt +++ b/themes/asf/index.html.xslt @@ -41,6 +41,19 @@ (feed) + + + message + + + + + + + + + +