def __init__(self, host): try: self.neograph = client.GraphDatabase(host) except client.NotFoundError: raise Neo4jDatabaseConnectionError(host) except ValueError: raise Neo4jDatabaseConnectionError(host)
def test_connection_cache_debug(self): from neo4jrestclient import options as clientCacheDebug clientCacheDebug.CACHE = True clientCacheDebug.DEBUG = True gdb = client.GraphDatabase(self.url) clientCacheDebug.CACHE = False clientCacheDebug.DEBUG = False self.assertEqual(gdb.url, self.url)
def setUp(self): self.cache_called = {} self.cache = options.CACHE self.cache_store = options.CACHE options.CACHE = True options.CACHE_STORE = FakeCache(self.cache_called) # reload modules now cache set reload(request) reload(client) self.gdb = client.GraphDatabase(NEO4J_URL)
def setUp(self): self.url = NEO4J_URL self.gdb = client.GraphDatabase(self.url)
def setUp(self): # A bit of monkey patching to emulate that we are inside IPython self.in_ipnb = query.in_ipnb query.in_ipnb = lambda: True self.url = NEO4J_URL self.gdb = client.GraphDatabase(self.url)
from neo4jrestclient import client from json import loads db = client.GraphDatabase("http://localhost:7474", username="******", password="******") from urllib2 import urlopen a = [u'war', u'pig'] a = map(lambda x: str(x), a) print a q = """MATCH (album:Album)-[r]-(tags) WHERE tags.name IN %s WITH album, COLLECT(tags) as tags, SUM(r.weight) as weight WHERE LENGTH(tags) = LENGTH(%s) RETURN album ORDER BY weight ASC LIMIT 10;""" % (a, a) results = db.query(q) print results tracklst = [] for each in results: s_id = each[0]['data']['s_id'] url = 'http://api.spotify.com/v1/albums/%s/tracks?limit=2' % (s_id[14:]) a = urlopen(url).read() a = loads(a) tracklst.extend((a['items'][0]['uri'], a['items'][1]['uri']))
from neo4jrestclient import client, constants import argparse import urllib import json gdb = client.GraphDatabase("http://localhost:7474/db/data/") def cypherQuery(idx, param): if idx == 'resources': qry = """START n=node:resources("resource:%s") MATCH other-[:submitted]->n RETURN other.submitter""" % urllib.quote_plus( param) elif idx == 'submitters': qry = """START n=node:submitters("submitter:%s") MATCH n-[:submitted]->other RETURN other.resource""" % urllib.quote_plus( param) cypher = gdb.extensions.CypherPlugin.execute_query nodes = cypher(query=qry, returns=constants.RAW) nodeList = nodes['data'] return nodeList def displayResults(resultList): for result in resultList: print urllib.unquote_plus(result[0]) def main(args): if args.res: nodeList = cypherQuery('resources', args.res)
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # import sys, time from neo4jrestclient import client NEO4J_URL = sys.argv[1] RUN_NAME = sys.argv[2] gdb = client.GraphDatabase(NEO4J_URL) # get the IDs of a few fixed nodes to be used for test queries below ret = gdb.query( q="""START root=node(0) MATCH root-[:HAS_RUN]->run WHERE run.name = "%s" RETURN run""" % RUN_NAME, returns=client.Node)[0] RUN_ID = ret[0]._get_id() ret = gdb.query( q="""START run=node(%d) MATCH run-[:RUN_FRAME]->frame WHERE frame.frame_id = %d RETURN frame""" % (RUN_ID, 8084), returns=client.Node)[0] FRAME_ID = ret[0]._get_id()
def connect(self, url, uname, pwd): self.gdb = client.GraphDatabase(url, username=uname, password=pwd) return self.gdb
from datetime import datetime from sets import Set import requests import spotipy import json import random from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger import sys,os import spotipy.util as util from sets import Set from random import shuffle from urllib2 import urlopen import pickle from neo4jrestclient import client db = client.GraphDatabase("http://54.84.132.154/db/data/", username="******", password="******") bag_of_words = list(pickle.load(open("bag_of_words.pkl", "rb" ))) def genre(request, genre_slug): context_dict = {} context_dict['result_list'] = None context_dict['query'] = None context_dict['bag_of_words'] = bag_of_words if request.method == 'POST': query = request.POST.get('query')
def test_connection_host(self): url = NEO4J_URL.replace("/db/data/", "") client.GraphDatabase(url)
def test_connection_https(self): url = NEO4J_URL.replace("http://", "https://") url = url.replace(":7474", ":7473") client.GraphDatabase(url)