Skip to content

Instantly share code, notes, and snippets.

@nonZero
Created November 18, 2015 10:15
Show Gist options
  • Save nonZero/7587d836b1c7f0ad6963 to your computer and use it in GitHub Desktop.
Save nonZero/7587d836b1c7f0ad6963 to your computer and use it in GitHub Desktop.
tryneo
def calc(s):
return 4
Authorities (file) => pick one
-->
Authority
-->
get_related_entities(authority)
-->
Records
Authority <> Record relationship (rel type)
============
1. from xml element > return Authority Node
1a. read xml and return properties in dict
1b. create the actual Node.
1c. save it
2. for an Authority Node, Return PrimoItem Nodes
2a. get id from Node
2b. get json from service for id
2c. build Nodes
2d. save
import unittest
from calculator import calc
class CalculatorTestCase(unittest.TestCase):
def test_simple_calc(self):
self.assertEqual(4, calc("2+2"))
def test_multi(self):
self.assertEqual(4, calc("2*2"))
if __name__ == '__main__':
unittest.main()
import py2neo
graph = py2neo.Graph("http://neo4j:n4j@localhost:7474/db/data/")
# for i in range(10):
# authority = py2neo.Node("Authority", name="Albert {}".format(i + 1))
# graph.create(authority)
# authority = py2neo.Node("Authority", name="Udi")
# graph.create(authority)
# for i in range(10):
# book = py2neo.Node("Record", name="Book #{}".format(i + 1))
# r = py2neo.Relationship(authority, "WROTE", book, at=1990 + i)
# graph.create(book, r)
#
# print("Done.")
# for record in graph.cypher.execute("Match (a)-[r:WROTE]->(b) return a.name, r.at;"):
# # print(type(record))
# print(record[0], record[1])
# # assert isinstance(n, py2neo.core.Node)
# # print(n['name'])
for record in graph.cypher.execute("Match (a)-[r:WROTE]->(b) return a;"):
# print(record[0])
n = record[0]
assert isinstance(n, py2neo.Node)
print(n['name'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment