Skip to content

Instantly share code, notes, and snippets.

View coolgarifTech's full-sized avatar

coolgarifTech

View GitHub Profile
@coolgarifTech
coolgarifTech / Example_CSVtoJSON_Parser.py
Last active December 21, 2015 10:39
An example python script to show how to parse CSV data into JSON. Used as part of project BorisBoard (http://www.borisboard.com).
# Part of BORIS BOARD Project
# Visit http://www.borisboard.com for more details
#
# By Coolgarif Tech Ltd
# Author: Richie Barter
# 21 Aug 2013
# Sample script for parsing a CSV into JSON for data vis
# Underlying DataSet
# Available here: http://data.london.gov.uk/datastore/package/street-trees-borough
@coolgarifTech
coolgarifTech / gist:5671097
Created May 29, 2013 15:17
Python syntax at the end of the script for firing the API and activating the Flask auto-reloader & debugger (very useful!)
if __name__ == '__main__':
app.debug = True
app.run()
@coolgarifTech
coolgarifTech / gist:5671071
Created May 29, 2013 15:14
HydraGraph script for exposing GraphDatabase in Neo4j using Python and Flask by Coolgarif Tech
from neo4jrestclient.client import GraphDatabase
from neo4jrestclient.constants import RAW
from neo4jrestclient.client import Node
from urlparse import urlparse
import re, json
from flask import Flask, Response, json, jsonify, request, Blueprint, render_template
app = Flask(__name__)
@coolgarifTech
coolgarifTech / gist:5671044
Created May 29, 2013 15:10
Cmd line to run the script, URL to test it in browser and expected well-formed JSON response with Nodes and relationships from the HydraGraph
$ python hydraGraph.py
# Navigate to this URL
http://127.0.0.1:5000/_api/hydraGraph?callback=khjsdbkjn
# FINAL JSON END POINT RESPONSE!!
# (Note the callback wrapper at the front!)
@coolgarifTech
coolgarifTech / gist:5671018
Created May 29, 2013 15:07
Creating the final Flask response
callbackWrapper = callbackArguments + "(" + result + ")"
resp = Response(callbackWrapper, status = 200, mimetype = 'application/json')
return resp
@coolgarifTech
coolgarifTech / gist:5671010
Created May 29, 2013 15:06
Creating the final JSON object as part of the request response in Flask
result = {
'nodes' : nodes,
'rels' : rels}
result = json.dumps(result)
@coolgarifTech
coolgarifTech / gist:5670986
Created May 29, 2013 15:04
An important part of the getRels() function in the script that uses the output from our Cypher query to establish the id's of the start and end point nodes in the various relationships in the graph
for rel in querySquenceObject:
r = rel.pop()
start = r.get('start')
end = r.get('end')
start = urlparse(start)
end = urlparse(end)
startNode = doRegEX(start)
endNode = doRegEX(end)
@coolgarifTech
coolgarifTech / gist:5670956
Created May 29, 2013 15:00
Example Neo4j Cypher query to return all the relationships in the sample graph
q = "START n=node(*) MATCH (n)-[r]->() RETURN r"
params = {}
querySquenceObject = db.query(q, params=params, returns=RAW)
@coolgarifTech
coolgarifTech / gist:5670920
Last active December 17, 2015 20:58
An important line in the script that calls the createNodeJSON function and then appends that the nodeJSON list that is being prepared
nodeJSON.append(createNodeJSON(name, uid, description))
def createNodeJSON(name, uid, description):
JSONObject = {
'name': name,
'id' : uid,
'description' : description
}
return JSONObject
@coolgarifTech
coolgarifTech / gist:5670892
Created May 29, 2013 14:53
A small helper function that strips the Node ID from the parsed URL using Regex statement
def doRegEX(urlString):
regex = re.compile("([^/]*)$")
stripedURLComponent = regex.search(urlString.path)
return stripedURLComponent.group(0)