Add support for new_feed_itmes
This commit is contained in:
parent
034404fd8a
commit
4b1ff4884e
@ -101,8 +101,8 @@ use for logging output. Note: this configuration value is processed
|
|||||||
<a href="http://docs.python.org/lib/ConfigParser-objects.html">raw</a></dd>
|
<a href="http://docs.python.org/lib/ConfigParser-objects.html">raw</a></dd>
|
||||||
<dt>feed_timeout</dt>
|
<dt>feed_timeout</dt>
|
||||||
<dd>Number of seconds to wait for any given feed</dd>
|
<dd>Number of seconds to wait for any given feed</dd>
|
||||||
<dt><del>new_feed_items</del></dt>
|
<dt>new_feed_items</dt>
|
||||||
<dd>Number of items to take from new feeds</dd>
|
<dd>Maximum number of items to include in the output from any one feed</dd>
|
||||||
<dt><ins>spider_threads</ins></dt>
|
<dt><ins>spider_threads</ins></dt>
|
||||||
<dd>The number of threads to use when spidering. When set to 0, the default,
|
<dd>The number of threads to use when spidering. When set to 0, the default,
|
||||||
no threads are used and spidering follows the traditional algorithm.</dd>
|
no threads are used and spidering follows the traditional algorithm.</dd>
|
||||||
|
@ -106,6 +106,7 @@ def __init__():
|
|||||||
define_planet('output_dir', 'output')
|
define_planet('output_dir', 'output')
|
||||||
define_planet('spider_threads', 0)
|
define_planet('spider_threads', 0)
|
||||||
|
|
||||||
|
define_planet_int('new_feed_items', 0)
|
||||||
define_planet_int('feed_timeout', 20)
|
define_planet_int('feed_timeout', 20)
|
||||||
define_planet_int('cache_keep_entries', 10)
|
define_planet_int('cache_keep_entries', 10)
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ def splice():
|
|||||||
|
|
||||||
# insert entry information
|
# insert entry information
|
||||||
items = 0
|
items = 0
|
||||||
|
count = {}
|
||||||
|
new_feed_items = config.new_feed_items()
|
||||||
for mtime,file in dir:
|
for mtime,file in dir:
|
||||||
if index != None:
|
if index != None:
|
||||||
base = os.path.basename(file)
|
base = os.path.basename(file)
|
||||||
@ -75,15 +77,23 @@ def splice():
|
|||||||
try:
|
try:
|
||||||
entry=minidom.parse(file)
|
entry=minidom.parse(file)
|
||||||
|
|
||||||
# verify that this entry is currently subscribed to
|
# verify that this entry is currently subscribed to and that the
|
||||||
|
# number of entries contributed by this feed does not exceed
|
||||||
|
# config.new_feed_items
|
||||||
entry.normalize()
|
entry.normalize()
|
||||||
sources = entry.getElementsByTagName('source')
|
sources = entry.getElementsByTagName('source')
|
||||||
if sources:
|
if sources:
|
||||||
ids = sources[0].getElementsByTagName('id')
|
ids = sources[0].getElementsByTagName('id')
|
||||||
if ids and ids[0].childNodes[0].nodeValue not in sub_ids:
|
if ids:
|
||||||
|
id = ids[0].childNodes[0].nodeValue
|
||||||
|
count[id] = count.get(id,0) + 1
|
||||||
|
if new_feed_items and count[id] > new_feed_items: continue
|
||||||
|
|
||||||
|
if id not in sub_ids:
|
||||||
ids = sources[0].getElementsByTagName('planet:id')
|
ids = sources[0].getElementsByTagName('planet:id')
|
||||||
if not ids: continue
|
if not ids: continue
|
||||||
if ids[0].childNodes[0].nodeValue not in sub_ids: continue
|
id = ids[0].childNodes[0].nodeValue
|
||||||
|
if id not in sub_ids: continue
|
||||||
|
|
||||||
# add entry to feed
|
# add entry to feed
|
||||||
feed.appendChild(entry.documentElement)
|
feed.appendChild(entry.documentElement)
|
||||||
|
@ -24,3 +24,11 @@ class SpliceTest(unittest.TestCase):
|
|||||||
self.assertEqual(8,len(doc.getElementsByTagName('entry')))
|
self.assertEqual(8,len(doc.getElementsByTagName('entry')))
|
||||||
self.assertEqual(3,len(doc.getElementsByTagName('planet:source')))
|
self.assertEqual(3,len(doc.getElementsByTagName('planet:source')))
|
||||||
self.assertEqual(11,len(doc.getElementsByTagName('planet:name')))
|
self.assertEqual(11,len(doc.getElementsByTagName('planet:name')))
|
||||||
|
|
||||||
|
def test_splice_new_feed_items(self):
|
||||||
|
config.load(configfile)
|
||||||
|
config.parser.set('Planet','new_feed_items','3')
|
||||||
|
doc = splice()
|
||||||
|
self.assertEqual(9,len(doc.getElementsByTagName('entry')))
|
||||||
|
self.assertEqual(4,len(doc.getElementsByTagName('planet:source')))
|
||||||
|
self.assertEqual(13,len(doc.getElementsByTagName('planet:name')))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user