diff options
| author | Alon Levy <alon@pobox.com> | 2015-02-05 15:40:44 +0200 |
|---|---|---|
| committer | Alon Levy <alon@pobox.com> | 2015-02-05 15:40:44 +0200 |
| commit | c6082885373acee08ecd746ddfa3b8dce1a0f8da (patch) | |
| tree | 95c12191c6ba5c2bea131b9e8f6df276dcf654c9 /tools/rhizi_tools_neo4j.py | |
| parent | 88b69cc593a1b8d265c133bbf71d4c8ce25dc4e3 (diff) | |
tools: split neo4j-cypher in preparation to make it reuse core server library
Diffstat (limited to 'tools/rhizi_tools_neo4j.py')
| -rw-r--r-- | tools/rhizi_tools_neo4j.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/rhizi_tools_neo4j.py b/tools/rhizi_tools_neo4j.py new file mode 100644 index 00000000..be8b4a5d --- /dev/null +++ b/tools/rhizi_tools_neo4j.py @@ -0,0 +1,43 @@ +import subprocess +import re +import json + +verbose = False + +BASE="http://rhizi.local:7474/db/data" + +def c(cmd, incoming=None): + if verbose: + print("executing %r" % cmd) + print(incoming) + p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if incoming: + p.stdin.write(incoming) + if p.stdin: + p.stdin.close() + p.wait() + ret = p.stdout.read() + return ret + +def curl(path, incoming): + return c(["curl", "-H", 'Accept: application/json', "-H", 'Content-Type: application/json', '-XPOST', '-d@-', path], + incoming=incoming) + +def transact(datum): + transaction_output = curl(BASE + "/transaction/", '{"statements": [ ] }') + commit = re.search("http://.*commit", transaction_output).group() + ret = curl(commit, json.dumps(datum)) + obj = json.loads(ret) + return obj + +def run(statements, one_at_a_time): + def single_request_data(statements): + return {'statements': [{'statement': s} for s in statements]} + results = [] + if one_at_a_time: + data = [single_request_data([statement]) for statement in statements] + else: + data = [single_request_data(statements)] + for datum in data: + results.append(transact(datum)) + return results |
