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