From 70f3a6104060bd22b6f1698bc7303dd746a45094 Mon Sep 17 00:00:00 2001 From: Thomas Wade Date: Tue, 25 Sep 2018 20:43:54 +0930 Subject: [PATCH] Make graph from scraped data --- scrape.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/scrape.py b/scrape.py index 4f84cb4..9ecb372 100755 --- a/scrape.py +++ b/scrape.py @@ -326,10 +326,35 @@ driver.quit() print('Done scraping, here\'s what we got') print('==================================') +for _, track in track_dict.items(): + graph.add_node( \ + track.url, \ + type='track', \ + label=str(track.title), \ + artist=str(track.artist), \ + title=str(track.title), \ + date=str(track.date), \ + tag=str(track.tag), \ + plays=str(track.plays), \ + likes=str(track.likes), \ + reposts=str(track.reposts), \ + comments=str(track.comments) \ + ) + for _, user in user_dict.items(): if not user.processed: continue + graph.add_node( \ + user.url_username, \ + type='user', \ + label=str(user.username), \ + track_count=str(user.track_count), \ + like_count=str(user.like_count), \ + following_count=str(user.following_count), \ + follower_count=str(user.follower_count) \ + ) + print(user.username) print(' ' + str(user.track_count) + ' tracks') print(' ' + str(user.like_count) + ' likes') @@ -338,12 +363,36 @@ for _, user in user_dict.items(): print(' Tracks:') for track in user.tracks: print(' ' + str(track)) + graph.add_edge( \ + user.url_username, \ + track, \ + label='created' + ) print(' Likes:') for track in user.likes: print(' ' + str(track)) + graph.add_edge( \ + user.url_username, \ + track, \ + label='likes' + ) print(' Followers:') for follower in user.followers: print(' ' + str(follower)) + graph.add_edge( \ + follower, \ + user.url_username, \ + label='follows' + ) print(' Following:') for followed in user.following: print(' ' + str(followed)) + graph.add_edge( \ + user.url_username, \ + follower, \ + label='follows' + ) + +print('Making graph...') +nx.write_gexf(graph, 'graph.gexf') +print('Graph written to \'graph.gexf\'')