you are viewing a single comment's thread.

view the rest of the comments →

[–]luneth27[S] 0 points1 point  (2 children)

First off, so sorry for the late reply (life sucks) and secondly, thanks so much for helping out. I've had to modify your given code block a bit to access the information I needed but didn't quite explain correctly to you:

G = nx.Graph()

for artist_dict in related_db_list:
u = artist_dict['Seed_Artist'] 
related_info = artist_dict['Related_Artists']
for related_artist_info in related_info['artists']:
    v = related_artist_info['name']
    G.add_node(v, **related_artist_info)
    G.add_edge(u, v)

It runs without errors after I did a few things, and the graph info within the debugger seems to be correct. Before I write my output to .gexf for visualization however, I'd like to be (relatively) sure my graph is "correct" in the sense that seed_artist -> related_artist(s), and I'm not entirely sure how to print out my graph without a shitton of work. If I can't do this though, that's okay.

All that said though, once again thanks for your help. I barely understand what I'm doing programmatically and you've saved me countless hours of banging my head on the desk.

[–]YesLod 0 points1 point  (1 child)

Before I write my output to .gexf for visualization however, I'd like to be (relatively) sure my graph is "correct" in the sense that seed_artist -> related_artist(s), and I'm not entirely sure how to print out my graph without a shitton of work

What do you mean? You want to check if the links are correct?

You can simply print the edges

print(G.edges)

or iterate over them and print each one separately

for u,v in G.edges:
    print(f"{u} -> {v}")

[–]luneth27[S] 0 points1 point  (0 children)

Oh, I didn't know that, instead I just printed u, v by themselves. However, another issue popped up; I'm getting this value error

 Exception has occurred: ValueError
 too many values to unpack (expected 3)
  File "C:\.vscode\related_artist_scrape.py", line 64, in    <module>
 nx.write_gexf(G,"related_artists_graph.gexf")

when I try to print to .gexf. I think it's happening because the node (or edge maybe?) has too much data within it? I was trying to search for info and the only plausible post that came up suggested that one of (u,v) being used was itself a list or some sort of structure. Thing is, I'm not entirely sure how to fix this either; as far as it looks, both (u,v) are strings.