Ejemplo n.º 1
0
from java.net import URL
from java.lang import System
from java.util import Date

from org.jdom.output import XMLOutputter
from org.jdom.contrib.beans import BeanMapper

from de.nava.informa.impl.basic import Item

# create test bean
item = Item("Bugo", "All about it!", URL("http://nava.de/huhu2002"))
item.setFound(Date())

# bean -> jdom
mapper = BeanMapper()
mapper.setBeanPackage("de.nava.informa.impl.basic")

# problems with mapping an URL object
mapper.ignoreProperty("link")

doc = mapper.toDocument(item)
o = XMLOutputter("  ", 1)
o.output(doc, System.out)

# may throw BeanMapperException
def addItem(channel, title, descr, link):
    item = Item(title, descr, URL(link))
    item.setFound(Date())
    channel.addItem(item)
from java.net import URL
from java.util import Date

from de.nava.informa.impl.basic import Channel
from de.nava.informa.impl.basic import Item

from de.nava.informa.exporters import RSS_0_91_Exporter


# create demo channel
channel = Channel("The Great Demo Channel")
item = Item("Bugo", "All about it!", URL("http://nava.de/huhu2002"))
item.setFound(Date())
channel.addItem(item)

# try to write out to file
exp_file = "test-rss091.xml"
print "Start to export channel to", exp_file
exporter = RSS_0_91_Exporter(exp_file)
exporter.write(channel)
print "Exporting finished."
from de.nava.informa.impl.basic import Channel
from de.nava.informa.impl.basic import Item


def addItem(channel, title, descr, link):
    item = Item(title, descr, URL(link))
    item.setFound(Date())
    channel.addItem(item)
    


# create demo channel
channel = Channel("The Great Demo Channel")
addItem(channel, "Bugo", "All about it!", "http://nava.de/huhu2002")
addItem(channel, "Python", "Instant Python updated", "http://nava.de/I9")

# convert to array
items = channel.getItems().toArray()
print "items", items

new_item = Item("NN", "Fresh", URL("http://new.com"))

new_items = []
new_items.append(new_item)
for item in items:
    new_items.append(item)

items = array(new_items, Object)
print "now items is", items

Ejemplo n.º 5
0
# update an existing index (adding a new document).

from java.net import URL
from java.util import Date

# from de.nava.informa.impl.basic import ChannelBuilder
# from de.nava.informa.utils import ChannelRegistry
from de.nava.informa.impl.basic import Item
from de.nava.informa.search import ItemDocument

from org.apache.lucene.analysis.standard import StandardAnalyzer
from org.apache.lucene.index import IndexWriter

# update (3rd arg) index writer in directory (first arg)
start_time = Date()
writer = IndexWriter("index", StandardAnalyzer(), 0)

# create new (dummy) item
item = Item("Informa released", "blubb", URL("http://nava.de/news/2002/06/25"))
item.setFound(Date())

# add new item to index
writer.addDocument(ItemDocument.makeDocument(item))

writer.optimize()
writer.close()
end_time = Date()

print "updating the index took %d milliseconds in total." \
      % (end_time.getTime() - start_time.getTime())