Tom,
executing that code, I get the following output:

[~/code/tompython] $rm -rf example_db/ && python testing.py
/Library/Python/2.6/site-packages/jpype/_pykeywords.py:18:
DeprecationWarning: the sets module is deprecated
  import sets
Created: http://pypi.python.org/
Created: http://diveintopython.org/
Created: http://pypi2.python.org/
get one:<Node id=3>
list_all_pages: <Node id=0>
list_all_pages: <Node id=1>
list_all_pages: <Node id=2>
list_all_pages: <Node id=3>
Traceback (most recent call last):
  File "testing.py", line 46, in <module>
    list_all_pages( )
  File "testing.py", line 40, in list_all_pages
    for node in db.node:
  File 
"/Library/Python/2.6/site-packages/Neo4j.py-0.1_SNAPSHOT-py2.6.egg/neo4j/_core.py",
line 307, in __getitem__
    return Node(self.__neo, self.__backend.getNodeById(id))
jpype._jexception.RuntimeExceptionPyRaisable:
org.neo4j.graphdb.NotFoundException: Node[4]


Just confirmed with Tobias that the iteration to Node[4] is a bug in
the Python bindings, since there is no node with that id in the db.
Will get back to you on that.

Cheers,

/peter neubauer

COO and Sales, Neo Technology

GTalk:      neubauer.peter
Skype       peter.neubauer
Phone       +46 704 106975
LinkedIn   http://www.linkedin.com/in/neubauer
Twitter      http://twitter.com/peterneubauer

http://www.neo4j.org               - Your high performance graph database.
http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.



On Mon, Aug 2, 2010 at 10:13 AM, Peter Neubauer
<[email protected]> wrote:
> Tom,
> I tried out you code, and with small adjustments, things are working
> for me. Only thing is that the db.node iterator seems to go up to id 4
> which does not exist in the db. See the code below. Will check that
> with Tobias and get some details on it.
>
> Does the code below work for you?
>
> /peter
>
>
>
> -------------------------------------------------------------
> import neo4j
>
> ######## A. DO SOME SETUP STUFF ############
> db = neo4j.GraphDatabase("example_db")
>
> pages = db.index("pages", create=True) # create an index called 'pages'
> url =  'http://pypi2.python.org/'
>
> def create_page(url, code='' ):
>       page_node = pages[url] # does this page exist yet?
>       if not page_node:
>               page_node = db.node(url=url, code=code) # create a page
>               pages[url] = page_node # Add to index
>               print "Created:" , url
>       else:
>               print "Exists already:" , url
>       return page_node
>
> ######## B. ADD SOME PAGES #################
> with db.transaction:
>       create_page( 'http://pypi.python.org/' )
>       create_page( 'http://diveintopython.org/' )
>       create_page( 'http://pypi2.python.org/' )
>       #create_python( 'http://stackoverflow.com/questions/tagged/python')
>
> ######## C. NOW GET SOME OUT ###############
> def get_one(url):
>       with db.transaction:
>               node = pages [url ]
>               if node == None:
>                 print "Node is none!"
>               return node
>
> print 'get one:' + str(get_one( url  )) # fails
>
> ######### D. TRY TO ITERATE ################
> def list_all_pages(  ):
>      #'Just iterate through the pages to make sure the data in in there...'
>       with db.transaction:
>               for node in db.node:
>                 print 'list_all_pages: ' + str(node)
>
> def delete_one( url ):
>  ''
>
> list_all_pages( )
>
>
> ----------------------------------------------------------------------
>
> Cheers,
>
> /peter neubauer
>
> COO and Sales, Neo Technology
>
> GTalk:      neubauer.peter
> Skype       peter.neubauer
> Phone       +46 704 106975
> LinkedIn   http://www.linkedin.com/in/neubauer
> Twitter      http://twitter.com/peterneubauer
>
> http://www.neo4j.org               - Your high performance graph database.
> http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party.
>
>
>
> On Fri, Jul 30, 2010 at 5:19 PM, Tom Smith <[email protected]> wrote:
>>
>> On 30 Jul 2010, at 15:35, [email protected] wrote:
>>
>>> graphdb = neo4j.GraphDatabase("db")
>>> with graphdb.transaction:
>>>  person = graphdb.node(name="Person")
>>>  peter = graphdb.node(name="Peter")
>>>  peter.IS_A(person)
>>>  print peter['name']
>>> graphdb.shutdown()
>>
>>
>>
>> Yes that works great... I think I'm having problems iterating the data once 
>> it is in. I'm trying to save data in from a simple web crawler... A and B 
>> below work OK. But C and D are hopeless. I'm assuming I don't HAVE to create 
>> a Traversal class to simply iterate through records... or is that not so?
>>
>> thanks, Tom
>>
>>
>>
>> ######## A. DO SOME SETUP STUFF ############
>> db = neo4j.GraphDatabase("example_db")
>>
>> pages = db.index("pages", create=True) # create an index called 'pages'
>> url =  'http://pypi.python.org/'
>>
>> def create_page(url, code='' ):
>>        page_node = pages[url] # does this page exist yet?
>>        if not page_node:
>>                page_node = db.node(url=url, code=code) # create a page
>>                pages[url] = page_node # Add to index
>>                print "Created:" , url
>>        else:
>>                print "Exists already:" , url
>>        return page_node
>>
>> ######## B. ADD SOME PAGES #################
>> with db.transaction:
>>        create_page( 'http://pypi.python.org/' )
>>        create_page( 'http://diveintopython.org/' )
>>        create_page( 'http://pypi.python.org/' )
>>        create_python( 'http://stackoverflow.com/questions/tagged/python')
>>
>> ######## C. NOW GET SOME OUT ###############
>> def get_one(url):
>>        with db.transaction:
>>                node = pages [url ]
>>                if node == None:
>>                        print "Node is none!"
>>                return node
>>
>> print get_one( url ) # fails
>>
>> ######### D. TRY TO ITERATE ################
>> def list_all_pages(  ):
>>        'Just iterate through the pages to make sure the data in in there...
>>        with db.transaction:
>>                for node in db.node:
>>                        er...
>>
>> def delete_one( url ):
>>        ''
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> Neo4j mailing list
>> [email protected]
>> https://lists.neo4j.org/mailman/listinfo/user
>>
>
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to