Example #1
0
	def __call__(self):
		actions = {"followings": scac.getFollowings,
					"followers": scac.getFollowers,
					"favorites": scac.getFavorites,
					"comments": scac.getComments,
					"tracks": scac.getTracks}
                initialResults = actions[self.action](self.artist)
                results = list(set([artist for artist in initialResults if scac.id2username(artist)]))
                return results
Example #2
0
def print_graph(G):
    for artist in G.nodes():
        if artist:
            try:
                username = scac.id2username(artist)
                followings = G.successors(artist)
                followers = G.predecessors(artist)
                try:    
                    print "\t", username + " has " + str(len(followings)) + " followings"
                    print "\t", username + " follows " + ", ".join(map(lambda x: scac.id2username(x), 
followings))
                except TypeError: 
                    print "No followings home!" 
                try:    
                    print "\t", username + " has " + str(len(followers)) + " followers"
                    print "\t", username + " is followed by " + ", ".join(map(lambda x: 
scac.id2username(x), followers))
                except TypeError:
                    print "No followers home!"
                    print "-"*40
            except UnicodeError:
                print "Artist's username not found"    
Example #3
0
	# list of artists we could not query
	unavailable_artists = []
	
	for t in range(depth):

		print "Iteration " + str(t)
		consumers = [Consumer(tasks, results) for i in xrange(num_consumers)]
		for w in consumers:
			w.start()

		# enqueue jobs
		num_jobs = 0
		artists_to_enqueue = list(set(artists_to_enqueue))

		for artist in artists_to_enqueue:
			username = scac.id2username(artist)
			try:
				print "\t", "Enqueueing: %s (%s)" % (username, artist)
				artistGraph.add_node(artist)
				bookTasks(tasks, artist)
				num_jobs += 1
			except UnicodeDecodeError:
				print "\t", "Artist ID %s is not query-able" % artist
				unavailable_artists.append(artist)

		print "\t", "--%d jobs enqueued" % num_jobs

		artists_to_enqueue = []

		# poison pill to kill off all workers when we finish
		for i in xrange(num_consumers):
Example #4
0
        artistGraph)) + " strongly connected components."

my_component = artistGraph

for component in nx.strongly_connected_component_subgraphs(artistGraph):
    if search.id in component:
        my_component = component

print "This artist's clique currently contains " + str(
    len(artistGraph)) + " artists."

# Go through the graph and compute each PR until it converges.
iterations = 10
print "Computing PageRank on your searched artist..."
computePR(my_component, 0.85, iterations)

prList = []

for artist in my_component.nodes():
    prList.append((artist, my_component.node[artist]['currPR']))

prList.sort(key=lambda tup: tup[1])  # Sort the list in place

prList.reverse()  # order by descending PR

print("Here are some artists similar to " + str(search.username))

for item in prList[0:10]:
    artist = scac.id2username(item[0])
    print artist, item[1]
Example #5
0
print "="*20

my_component = artistGraph

for component in nx.strongly_connected_component_subgraphs(artistGraph):
    if search.id in component:
        my_component = component

# Go through the graph and compute each PR until it converges.
iterations = 10
print "Computing PageRank on your searched artist..."
computePR(my_component , 0.85, iterations)

prList = []

for artist in my_component.nodes():
    prList.append((artist, my_component.node[artist]['currPR']))

prList.sort(key = lambda tup: tup[1]) # Sort the list in place

prList.reverse() # order by descending PR

print ("Here are some artists similar to " + str(search.username) )

for item in prList[0:10]:
    artist = scac.id2username(item[0])
    print artist, item[1]

        
                
Example #6
0
    # list of artists we could not query
    unavailable_artists = []

    for t in range(depth):

        print "Iteration " + str(t)
        consumers = [Consumer(tasks, results) for i in xrange(num_consumers)]
        for w in consumers:
            w.start()

        # enqueue jobs
        num_jobs = 0
        artists_to_enqueue = list(set(artists_to_enqueue))

        for artist in artists_to_enqueue:
            username = scac.id2username(artist)
            try:
                print "\t", "Enqueueing: %s (%s)" % (username, artist)
                artistGraph.add_node(artist)
                bookTasks(tasks, artist)
                num_jobs += 1
            except UnicodeDecodeError:
                print "\t", "Artist ID %s is not query-able" % artist
                unavailable_artists.append(artist)

        print "\t", "--%d jobs enqueued" % num_jobs

        artists_to_enqueue = []

        # poison pill to kill off all workers when we finish
        for i in xrange(num_consumers):
Example #7
0
profiles_to_enqueue = [search.id]

depth = 2
i = 0

# list of profiles we could not query
unavailable_profiles = []

for t in range(depth):

    print "Iteration " + str(t)

    profiles_to_enqueue = list(set(profiles_to_enqueue))

    for profile in profiles_to_enqueue:
        username = scac.id2username(profile)
        if username:
            print "\t", "Enqueueing: %s (%s)" % (username, profile)
            profileGraph.add_node(profile)

            newFollowings = scac.getFollowings(profile)
            print "New followings: " + ", ".join([scac.id2username(user) if isinstance(scac.id2username(user), str) else str(user) for user in newFollowings])
            scac.addFollowings(profile, newFollowings, profileGraph)
            profiles_to_enqueue.extend(newFollowings)

            newFollowers = scac.getFollowers(profile)
            print "New followers: " + ", ".join([scac.id2username(user) if isinstance(scac.id2username(user), str) else str(user) for user in newFollowers])
            scac.addFollowers(profile, newFollowers, profileGraph)
            profiles_to_enqueue.extend(newFollowers)

            newFavorites = scac.getFavorites(profile)
Example #8
0
artists_to_enqueue = [search.id]

depth = 2
i = 0

# list of artists we could not query
unavailable_artists = []

for t in range(depth):

    print "Iteration " + str(t)

    artists_to_enqueue = list(set(artists_to_enqueue))

    for artist in artists_to_enqueue:
        username = scac.id2username(artist)
        if username:
            print "\t", "Enqueueing: %s (%s)" % (username, artist)
            artistGraph.add_node(artist)

            newFollowings = scac.getFollowings(artist)
            print "New followings: " + ", ".join([scac.id2username(user) for user in newFollowings])
            scac.addFollowings(artist, newFollowings, artistGraph)
            artists_to_enqueue.extend(newFollowings)

            newFollowers = scac.getFollowers(artist)
            print "New followers: " + ", ".join([scac.id2username(user) for user in newFollowers])
            scac.addFollowers(artist, newFollowers, artistGraph)
            artists_to_enqueue.extend(newFollowers)

            newFavorites = scac.getFavorites(artist)
Example #9
0
profiles_to_enqueue = [search.id]

depth = 2
i = 0

# list of profiles we could not query
unavailable_profiles = []

for t in range(depth):

    print "Iteration " + str(t)

    profiles_to_enqueue = list(set(profiles_to_enqueue))

    for profile in profiles_to_enqueue:
        username = scac.id2username(profile)
        if username:
            print "\t", "Enqueueing: %s (%s)" % (username, profile)
                        profileGraph.add_node(profile)

            newFollowings = scac.getFollowings(profile)
            print "New followings: " + ", ".join([scac.id2username(user) if isinstance(scac.id2username(user), str) else str(user) for user in newFollowings])
            scac.addFollowings(profile, newFollowings, profileGraph)
            profiles_to_enqueue.extend(newFollowings)

            newFollowers = scac.getFollowers(profile)
            print "New followers: " + ", ".join([scac.id2username(user) if isinstance(scac.id2username(user), str) else str(user) for user in newFollowers])
            scac.addFollowers(profile, newFollowers, profileGraph)
            profiles_to_enqueue.extend(newFollowers)

            newFavorites = scac.getFavorites(profile)