-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
49 lines (35 loc) · 1.43 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
curl -v -X POST -H 'Content-Type: application/json' https://identity-dbtest.cluster-czkfhyvgzymk.us-east-1.neptune.amazonaws.com:8182/system -d '{ "action" : "initiateDatabaseReset" }'
pip install -U setuptools
pip install wheel
pip install gremlinpython
"""
import os
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.process.traversal import T
from gremlin_python.structure.graph import Graph
graph = Graph()
remoteConn = DriverRemoteConnection(os.getenv('GRAPH_DB'),'g')
g = graph.traversal().withRemote(remoteConn)
def add_node(g, p):
person = get_node(g, p['id'])
if person:
return person
o = g.addV(p['label']).property(T.id, p['id']).next()
for n, v in p.items():
if n not in ['id', 'label']:
g.V(o).property(n, v).next()
return o
def get_node(g, pid):
return [{**node.__dict__, **properties} for node in g.V(pid)
for properties in g.V(node).valueMap()]
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
# cleanup database
g.V().drop().iterate()
# clean properties
# g.V(person).properties().drop().iterate()
add_node(g, {"id": "irrlab", "label": "person", "name": "Ivan Rocha", "login": "irr"})
add_node(g, {"id": "irrlab2", "label": "person", "name": "Ivan Ribeiro Rocha", "login": "irocha"})
print(get_node(g, "irrlab"))
print(get_node(g, "irrlab2"))