-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhits.py
40 lines (31 loc) · 1 KB
/
hits.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#Run hits algorithm
import matplotlib.pyplot as plt
import networkx as nx
import spotipy
import pylab
spotify = spotipy.Spotify()
GRAPHFILE = 'digraph4' #name of graph you're reading in
NUMRANKED = 15
G = nx.read_gpickle(GRAPHFILE + '.pickle')
H = nx.hits(G)
hubs = H[0]
auth = H[1]
i = 1
print 'Top artists ranked by hub score'
print '==============================='
for k, v in sorted(hubs.items(), key=lambda t:t[1], reverse=True):
artist = spotify.artist(k)
print str(i) + '. ' + artist['name'] + ' {h: ' + str(v) + ', a: ' + str(auth[k]) + '}'
i += 1
if i > NUMRANKED:
break
i = 1
print ''
print 'Top artists ranked by authority score'
print '==============================='
for k, v in sorted(auth.items(), key=lambda t:t[1], reverse=True):
artist = spotify.artist(k)
print str(i) + '. ' + artist['name'] + '{a: ' + str(v) + ', h: ' + str(hubs[k]) + '}'
i += 1
if i > NUMRANKED:
break