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')))
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')))
def test_splice_unsub(self): config.load(configfile) config.parser.remove_section('tests/data/spider/testfeed2.atom') doc = splice() self.assertEqual(8, len(doc.getElementsByTagName('entry'))) self.assertEqual(3, len(doc.getElementsByTagName('planet:source'))) self.assertEqual(11, len(doc.getElementsByTagName('planet:name')))
def test_splice_unsub(self): config.load(configfile) config.parser.remove_section('tests/data/spider/testfeed2.atom') doc = splice() self.assertEqual(8,len(doc.getElementsByTagName('entry'))) self.assertEqual(3,len(doc.getElementsByTagName('planet:source'))) self.assertEqual(11,len(doc.getElementsByTagName('planet:name')))
def test_embedded_license(self): config.load(configfile) for testfeed in testfeeds: doc = splice.splice() splice.apply(doc.toxml('utf-8')) output = open(os.path.join(workdir, 'index.html')).read() self.assertTrue('Attribution 3.0 Unported' in output)
def test_invalid_default_license(self): config.load(configfile) for testfeed in testfeeds: doc = splice.splice() splice.apply(doc.toxml('utf-8')) output = open(os.path.join(workdir, 'index.html')).read() self.assertTrue('title="License information">License</a>' in output)
def test_splice(self): config.load(configfile) doc = splice() self.assertEqual(12,len(doc.getElementsByTagName('entry'))) self.assertEqual(4,len(doc.getElementsByTagName('planet:source'))) self.assertEqual(16,len(doc.getElementsByTagName('planet:name'))) self.assertEqual('test planet', doc.getElementsByTagName('title')[0].firstChild.nodeValue)
def test_default_license_lookup(self): config.load(configfile) expected_text = 'Reconocimiento-No comercial-Compartir bajo la' + \ ' misma licencia 2.5 Colombia' for testfeed in testfeeds: doc = splice.splice() splice.apply(doc.toxml('utf-8')) output = open(os.path.join(workdir, 'index.html')).read() self.assertTrue(expected_text in output)
def test_splice(self): config.load(configfile) doc = splice() self.assertEqual(12, len(doc.getElementsByTagName('entry'))) self.assertEqual(4, len(doc.getElementsByTagName('planet:source'))) self.assertEqual(16, len(doc.getElementsByTagName('planet:name'))) self.assertEqual( 'test planet', doc.getElementsByTagName('title')[0].firstChild.nodeValue)
def test_index_splice(self): import test_splice config.load(test_splice.configfile) index = idindex.create() self.assertEqual(12, len(index)) self.assertEqual('tag:planet.intertwingly.net,2006:testfeed1', index['planet.intertwingly.net,2006,testfeed1,1']) self.assertEqual('http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss', index['planet.intertwingly.net,2006,testfeed3,1']) for key in index.keys(): value = index[key] if value.find('testfeed2')>0: index[key] = value.swapcase() index.close() from planet.splice import splice doc = splice() self.assertEqual(8,len(doc.getElementsByTagName('entry'))) self.assertEqual(4,len(doc.getElementsByTagName('planet:source'))) self.assertEqual(12,len(doc.getElementsByTagName('planet:name')))
def test_index_splice(self): import test_splice config.load(test_splice.configfile) index = idindex.create() self.assertEqual(12, len(index)) self.assertEqual('tag:planet.intertwingly.net,2006:testfeed1', index['planet.intertwingly.net,2006,testfeed1,1']) self.assertEqual( 'http://intertwingly.net/code/venus/tests/data/spider/testfeed3.rss', index['planet.intertwingly.net,2006,testfeed3,1']) for key in index.keys(): value = index[key] if value.find('testfeed2') > 0: index[key] = value.swapcase() index.close() from planet.splice import splice doc = splice() self.assertEqual(8, len(doc.getElementsByTagName('entry'))) self.assertEqual(4, len(doc.getElementsByTagName('planet:source'))) self.assertEqual(12, len(doc.getElementsByTagName('planet:name')))
import feedparser for source in glob.glob(os.path.join(work, 'sources/*')): feed = feedparser.parse(source).feed if feed.has_key('title'): config.parser.set('Planet','name',feed.title_detail.value) if feed.has_key('link'): config.parser.set('Planet','link',feed.link) if feed.has_key('author_detail'): if feed.author_detail.has_key('name'): config.parser.set('Planet','owner_name',feed.author_detail.name) if feed.author_detail.has_key('email'): config.parser.set('Planet','owner_email',feed.author_detail.email) from planet import splice doc = splice.splice() sources = doc.getElementsByTagName('planet:source') if hide_planet_ns and len(sources) == 1: source = sources[0] feed = source.parentNode child = feed.firstChild while child: next = child.nextSibling if child.nodeName not in ['planet:source','entry']: feed.removeChild(child) child = next while source.hasChildNodes(): child = source.firstChild source.removeChild(child) feed.insertBefore(child, source)
source=open('tests/data/spider/config.ini') dest1=open('tests/data/splice/config.ini', 'w') dest1.write(source.read().replace('/work/spider/', '/data/splice/')) dest1.close() source.seek(0) dest2=open('tests/work/apply_config.ini', 'w') dest2.write(source.read().replace('[Planet]', '''[Planet] output_theme = asf output_dir = tests/work/apply''')) dest2.close() source.close() # copy splice output to apply input from planet import splice file=open('tests/data/apply/feed.xml', 'w') config.load('tests/data/splice/config.ini') data=splice.splice().toxml('utf-8') file.write(data) file.close() # copy apply output to config/reading-list input config.load('tests/work/apply_config.ini') splice.apply(data) shutil.move('tests/work/apply/opml.xml', 'tests/data/config') shutil.rmtree('tests/work') import runtests
from planet import config config.load(config_file or 'config.ini') if verbose: import planet planet.getLogger('DEBUG', config.log_format()) if not offline: from planet import spider try: spider.spiderPlanet(only_if_new=only_if_new) except Exception, e: print e from planet import splice doc = splice.splice() if debug_splice: from planet import logger logger.info('writing debug.atom') debug = open('debug.atom', 'w') try: from lxml import etree from StringIO import StringIO tree = etree.tostring(etree.parse(StringIO(doc.toxml()))) debug.write(etree.tostring(tree, pretty_print=True)) except: debug.write(doc.toprettyxml(indent=' ', encoding='utf-8')) debug.close splice.apply(doc.toxml('utf-8'))
dest1 = open('tests/data/splice/config.ini', 'w') dest1.write(source.read().replace('/work/spider/', '/data/splice/')) dest1.close() source.seek(0) dest2 = open('tests/work/apply_config.ini', 'w') dest2.write(source.read().replace( '[Planet]', '''[Planet] output_theme = asf output_dir = tests/work/apply''')) dest2.close() source.close() # copy splice output to apply input from planet import splice file = open('tests/data/apply/feed.xml', 'w') config.load('tests/data/splice/config.ini') data = splice.splice().toxml('utf-8') file.write(data) file.close() # copy apply output to config/reading-list input config.load('tests/work/apply_config.ini') splice.apply(data) shutil.move('tests/work/apply/opml.xml', 'tests/data/config') shutil.rmtree('tests/work') import runtests