Skip to content

Instantly share code, notes, and snippets.

@davidfauth

davidfauth/testgist

Created Apr 24, 2020
Embed
What would you like to do?
import json
from py2neo import authenticate, Graph, NodeSelector, Node, Relationship
import sys
import time
from neo4j import GraphDatabase
def run_cypher_query(tx, query):
return tx.run(query)
host="x.x.x.x:7474"
url = "http://x.x.x.x:7474/"
username="neo4j"
password="password"
authenticate(host, username, password)
graph = Graph(url + "/db/data/")
query="MATCH (p:PHONE) return p limit 10;"
#a = graph.run(query)
#results=a.data()
#for r in results:
# data = {}
# result_dict = dict(r)
# print(result_dict)
# for k,v in result_dict.items():
# if isinstance(v, Node) or isinstance(v, Relationship):
# for inner_k, inner_v in dict(v).items():
# data[k + "." + inner_k] = inner_v
# else:
# data[k] = v
# data["_raw"] = r
# print(data)
print("Python Driver")
uri = "bolt://x.x.x.x:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "<enteryourpassword>"))
with driver.session() as session:
results=session.run(query)
for r in results.data():
data = {}
result_dict = dict(r)
print(result_dict.items())
for k,v in result_dict.items():
for inner_k, inner_v in dict(v).items():
data[k + "." + inner_k] = inner_v
data["_raw"] = r
print(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment