import connector_neo4j import argparse import os from pprint import pprint # don't look at this for good code examples # this needs the following three env variables set PASSWORD=os.environ['NEO_PASSWORD'] USER=os.environ['NEO_USER'] NEO_URL=os.environ['NEO_URL'] parser = argparse.ArgumentParser( description='The start of emails search') parser.add_argument( 'emails', metavar='email', nargs='+', help='The start of an email to search for in Neo like jpenner') args = parser.parse_args() def main(): for email in args.emails: print('----') match_email_prefix(email) print('----') @connector_neo4j.Neo4jSession() def match_email_prefix(prefix): print('Match all emails starting with: '+prefix) session = connector_neo4j.get_session() print('----------') query = "MATCH (i:Identity) WHERE i.email STARTS WITH $prefix RETURN i" results = session.run(query, prefix = prefix) for result in results: items = result['i'] print('name: ' + items['name']) print('identity id: ' + items['id']) print('email: ' + items['email']) print('createdAt: ' + str(items['createdAt'])) if 'invitation_id' in items: print('invitation id: ' + items['invitation_id']) if 'auth0UserCreatedBy' in items: print('auth0UserCreatedBy: ' + items['auth0UserCreatedBy']) if 'auth0UserId' in items: print('auth0UserId: ' + items['auth0UserId']) if 'updatedBy' in items: print('updatedBy: ' + items['updatedBy']) if 'updatedOn' in items: print('updatedOn: ' + str(items['updatedOn'])) if 'active' in items: print('Active: ' + items['active']) if 'defaultBrand' in items: print('defaultBrand: ' + items['defaultBrand']) query = """MATCH (u:Identity)-[:HAS_PROFILE]->(p:Profile) WHERE u.id = $id RETURN p as profile""" result = session.run( query, id=items['id']) for profiles in result: profile = profiles['profile'] ptype = profile['profileType'] id = profile['profileId'] label = '' if ptype == 'LabelProfile': label = ', Name: ' + profile['profileName'] print('profile type: ' + ptype + ' id: ' + str(id) + label) # pprint(vars(result)) print('----------') @connector_neo4j.Neo4jSession(transaction=True) def cleanup(): session = connector_neo4j.get_session() #session.run('MATCH (n:Person) DETACH DELETE n') # url started with bolt originally if __name__ == '__main__': connector_neo4j.configure( NEO_URL, USER, PASSWORD, connector_neo4j.SessionStorageMode.SINGLE ) main()