Skip to content

Instantly share code, notes, and snippets.

@jexp
Last active May 8, 2023 09:30
Show Gist options
  • Save jexp/320521a881113b853a2f97cc867a25bf to your computer and use it in GitHub Desktop.
Save jexp/320521a881113b853a2f97cc867a25bf to your computer and use it in GitHub Desktop.
BlueSky User Interactions Neo4j Import, data collection courtesy https://bsky.jazco.dev/
create constraint user_key if not exists for (u:User) require (u.key) is unique;
// add nodes
call apoc.load.json("https://bsky.jazco.dev/exported_graph_minified.json","$.nodes")
yield value as nv
call { with nv
merge (n:User {key:nv.key})
on create set n += apoc.map.clean(nv.attributes,["key"],[])
} in transactions of 10000 rows;
// add relationships
call apoc.load.json("https://bsky.jazco.dev/exported_graph_minified.json","$.edges") yield value as ev
call { with ev
match (source:User {key:ev.source}),(target:User {key:ev.target})
merge (source)-[r:INTERACTED {key:ev.key}]-(target)
set r += ev.attributes
} in transactions of 20000 rows;
// merge duplicate nodes
match (u:User)
with u.label as label, count(*) as count, collect(u) as users
where count > 1
call apoc.refactor.mergeNodes(users) yield node
return node;
create constraint user_label if not exists for (u:User) require (u.label) is unique;
/*
call apoc.load.json("https://bsky.jazco.dev/exported_graph_minified.json") yield value
return value.nodes[0], value.edges[0];
*/
// Load threads, like the hellthread:
call apoc.load.json("https://bsky-search.jazco.io/thread?authorHandle=pet.bun.how&postID=3juqpknhkxp2o&layout=true","$") yield value as entry
call { with entry
with entry, entry.post as post
merge (p:Post {id:post.id})
set
p += entry {.depth, .x, .y},
p += post { .root_post_id, .has_embedded_media, created_at: datetime(post.created_at), .text}
merge (parent:Post {id:post.parent_post_id})
merge (p)-[:PARENT]->(parent)
with *
match (u:User { label: entry.author_handle})
set u.did = post.author_did
merge (u)-[:POSTED]->(p)
} in transactions of 10000 rows;;
@jexp
Copy link
Author

jexp commented Apr 29, 2023

Visualization in Neo4j bloom with color and sizes

You can import it in Neo4j Sandbox (3 days) or AuraDB Free (perpetually free)
I made the data also available on our demo server with read-only username, password, database all "bluesky".

bsky-central-neo4j-bloom

@jexp
Copy link
Author

jexp commented Apr 30, 2023

Example query:

match path = (u:User)-[:INTERACTED*2]-() 
where u.label = 'jaz.bsky.social' and all(r in relationships(path) where r.weight > 25)
return path limit 100

bsky-neo4j-browser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment