This is an example project combining Neo4j, Python and Github API
This project demostrates:
-
Call Github API using Python multithreading
-
Collect data from threads and output to a
followers.csv
-
Use
followers.csv
which containsUser
data andFollower
relationships to output CSVs distict for each:users.csv
- distinct Usersfollows.csv
- distinct mappings from User-to-Follows
-
Load CSVs into Neo4j
-
Create Neo4j relationships
-
Query Neo4j using the Python
neo4j-driver
client -
Write queried data to write
json
-
Use
json
to generate aD3Js
web graph
The current web/d3-results.json
is already populated with my data, so just run:
cd web
npm install http-server
http-server
Create a Github API token - this will be needed to make requests if making over 60 requests an hour, the unauthenticated rate limit
pip install -r requirements.txt
Populate CSVs for the Github User whose followers is being populated
python code/followers.py --username <username>
python code/follows.py --username <username>
python code/users.py --username <username>
Data can be loaded into Neo4j using the below queries
After data is loaded, run this command to populate web/d3-results.json
.
Environment varialbe NEO4J_PASSWORD
will need to be set for the Neo4j database connection in query.py
python query.py
Start Node server and see data with D3Js
cd web
npm install http-server
http-server
CSV must first be placed in the Neo4j /import/
dir:
/Users/aaron/Library/Application\ Support/Neo4j\ Desktop/Application/neo4jDatabases/database-0bf7614b-cb8d-405e-baef-e1b94485e662/installation-3.3.5/import/
Load Users
table using CSV:
LOAD CSV WITH HEADERS FROM "file:///users.csv" AS row
CREATE (u:User)
SET u = row
Load Follows
table using CSV:
LOAD CSV WITH HEADERS FROM "file:///follows.csv" AS row
CREATE (u:Follows)
SET u = row
Create FOLLOWS
relationships using previous 2 tables:
MATCH (u:User),(f:Follows), (u2:User)
WHERE u.login = f.login
AND f.follows = u2.login
CREATE (u)-[:FOLLOWS]->(u2)
First delete relationships:
MATCH ()-[r:FOLLOWS]-()
DELETE r
Then delete tables:
MATCH (r:User)
DELETE r
MATCH (r:Follows)
DELETE r
BSD-2
Contact me if you found this interesting
Add more end-to-end Neo4j Graph Database examples