Preparing to get the data from Spotify
Next thing that I needed to do was to login to the Spotify developer portal at https://developer.spotify.com/ and add another application. This basically creates a little sandbox environment for our future application to talk to the Spotify API. It's super easy to do: just go to https://developer.spotify.com/dashboard/applications and create a new application:
Importing the data from Spotify using python
Side note: if you want to take a look at the different methods that get called in the script, you can use something like pycallgraph. I thought it was very useful to illustrate how the different parts of the script interact and refer to one another. Obviously, we would want to actually look at that in a proper Neo4j graph some day - but that's a different blogpost, methinks!
So now the data is nice and comfy in our Neo4j databae, and we can take a stab at exploring this!
Exploring the Spotify playlist in Neo4j
Just to get acquainted with our new best friend, the Neo4j database, here's what the model looks like:
And so we can start running some queries. This one gives me a feel for the data quantities:
match (n)and gives me this result:
return "Node" as Type,labels(n) as Name,count(n) as Count
return "Relationship" as Type,type(r) as Name, count(r) as Count
So let's take a look at some links between artists - typically something that is very difficult to do on other data platforms, and very straightforward in Neo4j. Let's for the links between "BRUCE" and "TOM":
match (a1:Artist), (a2:Artist), path = allshortestpaths ((a1)-[*]-(a2))this gives me an interesting subgraph:
where toUpper(a1.name) contains "BRUCE"
and toUpper(a2.name) contains "TOM"
match (a:Artist)return a.name as ArtistName, a.`pagerank-spotify` as SpotifyPagerank, a.`pagerank-workedwith` as WorkedWithPageRank, a.`pagerank-similarity` as PageRankSimilarityorder by a.`pagerank-spotify` desclimit 10;
And it's very easy to explore the immediate surroundings of some of these artists:
match path = ((a:Artist)-[*..2]-(conn))
order by a.`pagerank-spotify` desc
Which gives me this subgraph:
return a.name as Artist, count(t) as NumberOfTracks
order by NumberOfTracks desc
match (ar:Artist)<--(t:Track)-->(al:Album)-->(a)return ar.name, al.name, count(t)order by count(t) desclimit 10
Using NeoDash to create a Spotify Dashboard
- behave in a certain way based on the type that you give it. You can make
- line chart,
- bar charts, and
- markdown text sections
- have a few parameters that you need to specify. More specifically, you will want to "instruct" each rectangle section to query your Neo4j instance based on some cypher query that you specify.