Make graph from scraped data

This commit is contained in:
Thomas Wade 2018-09-25 20:43:54 +09:30
parent f0ba07e013
commit 70f3a61040

View File

@ -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\'')