Activity threshold and http status messages

This commit is contained in:
Sam Ruby 2006-09-03 08:52:09 -04:00
parent c71a974928
commit 5d7bd64342
5 changed files with 61 additions and 2 deletions

View File

@ -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

View File

@ -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')

View File

@ -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('''<feed xmlns:planet="%s"

View File

@ -0,0 +1,16 @@
<!--
Description: message
Expect: Channels[0]['message'] == 'foo' and Items[0]['channel_message'] == 'foo'
-->
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<source>
<planet:message>foo</planet:message>
</source>
</entry>
<planet:source xmlns:planet='http://planet.intertwingly.net/'>
<planet:message>foo</planet:message>
</planet:source>
</feed>

View File

@ -41,6 +41,19 @@
<img src="images/feed-icon-10x10.png" alt="(feed)"/>
</a>
<a href="{atom:link[@rel='alternate']/@href}">
<xsl:choose>
<xsl:when test="planet:message">
<xsl:attribute name="class">message</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="planet:message"/>
</xsl:attribute>
</xsl:when>
<xsl:when test="atom:title">
<xsl:attribute name="title">
<xsl:value-of select="atom:title"/>
</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:value-of select="planet:name"/>
</a>
</li>