Skip to content

Instantly share code, notes, and snippets.

#Store network data as plain text file to be analyzed later
twitter_net._name=seed+'_k'+str(k) # Name the network after the seed and the number of snowball rounds
NX.write_edgelist(twitter_net,path='drewconway_k2.edgelist',delimiter='\t')
#Store network data as plain text file to be analyzed later
twitter_net._name=seed+'_k'+str(k) # Name the network after the seed and the number of snowball rounds
NX.write_edgelist(twitter_net,path='drewconway_k2.edgelist',delimiter='\t')
def snowball_search(network,twitter_api,seed_user,cur_round):
# Snowball uses create_egonet to generate new structure
users=nodes_at_degree(network,cur_round) # Get all the users at the current round degree
for u in users:
time.sleep(5) # Wait five seconds in between to not hammer Twitter servers (H/T: @amyiris)
search_results=create_egonet(twitter_api,u)
network=NX.compose(network,search_results)
return network
def create_egonet(twitter_api,seed_user):
def snowball_build(twitter_api,seed_user,rounds):
# Main network building loop
for r in range(0,rounds):
if r<1:
# Create initial egonet
net=create_egonet(twitter_api,seed_user)
if net.size()>99:
print 'Running this script will exceed your Twitter API rate limit. You already have enough friends!'
break
else:
import twitter
import networkx as NX
import time
# Create an authenticated Api object in order to download user data
api_user='your_twitter_id'
api_pswd='your_twitter_password'
api=twitter.Api(username=api_user,password=api_pswd)
# The seed user to be analyzed
import twitter
import networkx as NX
# Create an authenticated Api object in order to download user data
api_user='drewconway'
api_pswd='peugeot'
api=twitter.Api(username=api_user,password=api_pswd)
# The seed user to be analyzed
seed='drewconway'